Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3281466
ArcanistUnexpectedReturnValueXHPASTLinterRule.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
ArcanistUnexpectedReturnValueXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistUnexpectedReturnValueXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
92
;
public
function
getLintName
(
)
{
return
pht
(
'Unexpected `%s` Value'
,
'return'
)
;
}
public
function
getLintSeverity
(
)
{
return
ArcanistLintSeverity
::
SEVERITY_WARNING
;
}
public
function
process
(
XHPASTNode
$root
)
{
$methods
=
$root
->
selectDescendantsOfType
(
'n_METHOD_DECLARATION'
)
;
foreach
(
$methods
as
$method
)
{
$method_name
=
$method
->
getChildOfType
(
2
,
'n_STRING'
)
->
getConcreteString
(
)
;
switch
(
strtolower
(
$method_name
)
)
{
case
'__construct'
:
case
'__destruct'
:
$returns
=
$method
->
selectDescendantsOfType
(
'n_RETURN'
)
;
foreach
(
$returns
as
$return
)
{
$return_value
=
$return
->
getChildByIndex
(
0
)
;
if
(
$return_value
->
getTypeName
(
)
==
'n_EMPTY'
)
{
continue
;
}
if
(
$this
->
isInAnonymousFunction
(
$return
)
)
{
continue
;
}
$this
->
raiseLintAtNode
(
$return
,
pht
(
'Unexpected `%s` value in `%s` method.'
,
'return'
,
$method_name
)
)
;
}
break
;
}
}
}
private
function
isInAnonymousFunction
(
XHPASTNode
$node
)
{
while
(
$node
)
{
if
(
$node
->
getTypeName
(
)
==
'n_FUNCTION_DECLARATION'
&&
$node
->
getChildByIndex
(
2
)
->
getTypeName
(
)
==
'n_EMPTY'
)
{
return
true
;
}
$node
=
$node
->
getParentNode
(
)
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Mar 23, 22:31 (1 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1120799
Default Alt Text
ArcanistUnexpectedReturnValueXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment