Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2891340
ArcanistExitExpressionXHPASTLinterRule.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
ArcanistExitExpressionXHPASTLinterRule.php
View Options
<?php
/**
* Exit is parsed as an expression, but using it as such is almost always
* wrong. That is, this is valid:
*
* strtoupper(33 * exit - 6);
*
* When exit is used as an expression, it causes the program to terminate with
* exit code 0. This is likely not what is intended; these statements have
* different effects:
*
* exit(-1);
* exit -1;
*
* The former exits with a failure code, the latter with a success code!
*/
final
class
ArcanistExitExpressionXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
17
;
public
function
getLintName
(
)
{
return
pht
(
'`%s` Used as Expression'
,
'exit'
)
;
}
public
function
process
(
XHPASTNode
$root
)
{
$unaries
=
$root
->
selectDescendantsOfType
(
'n_UNARY_PREFIX_EXPRESSION'
)
;
foreach
(
$unaries
as
$unary
)
{
$operator
=
$unary
->
getChildByIndex
(
0
)
->
getConcreteString
(
)
;
if
(
strtolower
(
$operator
)
===
'exit'
)
{
if
(
$unary
->
getParentNode
(
)
->
getTypeName
(
)
!==
'n_STATEMENT'
)
{
$this
->
raiseLintAtNode
(
$unary
,
pht
(
'Use `%s` as a statement, not an expression.'
,
'exit'
)
)
;
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 15:05 (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1120414
Default Alt Text
ArcanistExitExpressionXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment