Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889020
ArcanistTautologicalExpressionXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
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
Jan 19 2025, 11:04 (5 w, 17 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1123994
Default Alt Text
ArcanistTautologicalExpressionXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment