Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22422465
ArcanistSlownessXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
ArcanistSlownessXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistSlownessXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
36
;
public
function
getLintName
()
{
return
pht
(
'Slow Construct'
);
}
public
function
getLintSeverity
()
{
return
ArcanistLintSeverity
::
SEVERITY_WARNING
;
}
public
function
process
(
XHPASTNode
$root
)
{
$this
->
lintStrstrUsedForCheck
(
$root
);
$this
->
lintStrposUsedForStart
(
$root
);
}
private
function
lintStrstrUsedForCheck
(
XHPASTNode
$root
)
{
$expressions
=
$root
->
selectDescendantsOfType
(
'n_BINARY_EXPRESSION'
);
foreach
(
$expressions
as
$expression
)
{
$operator
=
$expression
->
getChildOfType
(
1
,
'n_OPERATOR'
);
$operator
=
$operator
->
getConcreteString
();
if
(
$operator
!==
'==='
&&
$operator
!==
'!=='
)
{
continue
;
}
$false
=
$expression
->
getChildByIndex
(
0
);
if
(
$false
->
getTypeName
()
===
'n_SYMBOL_NAME'
&&
$false
->
getConcreteString
()
===
'false'
)
{
$strstr
=
$expression
->
getChildByIndex
(
2
);
}
else
{
$strstr
=
$false
;
$false
=
$expression
->
getChildByIndex
(
2
);
if
(
$false
->
getTypeName
()
!==
'n_SYMBOL_NAME'
||
$false
->
getConcreteString
()
!==
'false'
)
{
continue
;
}
}
if
(
$strstr
->
getTypeName
()
!==
'n_FUNCTION_CALL'
)
{
continue
;
}
$name
=
strtolower
(
$strstr
->
getChildByIndex
(
0
)->
getConcreteString
());
if
(
$name
===
'strstr'
||
$name
===
'strchr'
)
{
$this
->
raiseLintAtNode
(
$strstr
,
pht
(
'Use `%s` for checking if the string contains something.'
,
'strpos'
));
}
else
if
(
$name
===
'stristr'
)
{
$this
->
raiseLintAtNode
(
$strstr
,
pht
(
'Use `%s` for checking if the string contains something.'
,
'stripos'
));
}
}
}
private
function
lintStrposUsedForStart
(
XHPASTNode
$root
)
{
$expressions
=
$root
->
selectDescendantsOfType
(
'n_BINARY_EXPRESSION'
);
foreach
(
$expressions
as
$expression
)
{
$operator
=
$expression
->
getChildOfType
(
1
,
'n_OPERATOR'
);
$operator
=
$operator
->
getConcreteString
();
if
(
$operator
!==
'==='
&&
$operator
!==
'!=='
)
{
continue
;
}
$zero
=
$expression
->
getChildByIndex
(
0
);
if
(
$zero
->
getTypeName
()
===
'n_NUMERIC_SCALAR'
&&
$zero
->
getConcreteString
()
===
'0'
)
{
$strpos
=
$expression
->
getChildByIndex
(
2
);
}
else
{
$strpos
=
$zero
;
$zero
=
$expression
->
getChildByIndex
(
2
);
if
(
$zero
->
getTypeName
()
!==
'n_NUMERIC_SCALAR'
||
$zero
->
getConcreteString
()
!==
'0'
)
{
continue
;
}
}
if
(
$strpos
->
getTypeName
()
!==
'n_FUNCTION_CALL'
)
{
continue
;
}
$name
=
strtolower
(
$strpos
->
getChildByIndex
(
0
)->
getConcreteString
());
if
(
$name
===
'strpos'
)
{
$this
->
raiseLintAtNode
(
$strpos
,
pht
(
'Use `%s` for checking if the string starts with something.'
,
'strncmp'
));
}
else
if
(
$name
===
'stripos'
)
{
$this
->
raiseLintAtNode
(
$strpos
,
pht
(
'Use `%s` for checking if the string starts with something.'
,
'strncasecmp'
));
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 28, 03:22 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1207280
Default Alt Text
ArcanistSlownessXHPASTLinterRule.php (3 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline