Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22416161
ArcanistTautologicalExpressionXHPASTLinterRule.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
1 KB
Referenced Files
None
Subscribers
None
ArcanistTautologicalExpressionXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistTautologicalExpressionXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
20
;
public
function
getLintName
()
{
return
pht
(
'Tautological Expression'
);
}
public
function
process
(
XHPASTNode
$root
)
{
$expressions
=
$root
->
selectDescendantsOfType
(
'n_BINARY_EXPRESSION'
);
static
$operators
=
array
(
'-'
=>
true
,
'/'
=>
true
,
'-='
=>
true
,
'/='
=>
true
,
'<='
=>
true
,
'<'
=>
true
,
'=='
=>
true
,
'==='
=>
true
,
'!='
=>
true
,
'!=='
=>
true
,
'>='
=>
true
,
'>'
=>
true
,
);
static
$logical
=
array
(
'||'
=>
true
,
'&&'
=>
true
,
);
foreach
(
$expressions
as
$expr
)
{
$operator
=
$expr
->
getChildByIndex
(
1
)->
getConcreteString
();
if
(!
empty
(
$operators
[
$operator
]))
{
$left
=
$expr
->
getChildByIndex
(
0
)->
getSemanticString
();
$right
=
$expr
->
getChildByIndex
(
2
)->
getSemanticString
();
if
(
$left
===
$right
)
{
$this
->
raiseLintAtNode
(
$expr
,
pht
(
'Both sides of this expression are identical, so it always '
.
'evaluates to a constant.'
));
}
}
if
(!
empty
(
$logical
[
$operator
]))
{
$left
=
$expr
->
getChildByIndex
(
0
)->
getSemanticString
();
$right
=
$expr
->
getChildByIndex
(
2
)->
getSemanticString
();
// NOTE: These will be null to indicate "could not evaluate".
$left
=
$this
->
evaluateStaticBoolean
(
$left
);
$right
=
$this
->
evaluateStaticBoolean
(
$right
);
if
((
$operator
===
'||'
&&
(
$left
===
true
||
$right
===
true
))
||
(
$operator
===
'&&'
&&
(
$left
===
false
||
$right
===
false
)))
{
$this
->
raiseLintAtNode
(
$expr
,
pht
(
'The logical value of this expression is static. '
.
'Did you forget to remove some debugging code?'
));
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 28, 01:31 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1206264
Default Alt Text
ArcanistTautologicalExpressionXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline