Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3493389
ArcanistStaticThisXHPASTLinterRule.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
ArcanistStaticThisXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistStaticThisXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
13
;
public
function
getLintName
(
)
{
return
pht
(
'Use of %s in Static Context'
,
'$this'
)
;
}
public
function
process
(
XHPASTNode
$root
)
{
$classes
=
$root
->
selectDescendantsOfType
(
'n_CLASS_DECLARATION'
)
;
foreach
(
$classes
as
$class
)
{
$methods
=
$class
->
selectDescendantsOfType
(
'n_METHOD_DECLARATION'
)
;
foreach
(
$methods
as
$method
)
{
$attributes
=
$method
->
getChildByIndex
(
0
,
'n_METHOD_MODIFIER_LIST'
)
->
selectDescendantsOfType
(
'n_STRING'
)
;
$method_is_static
=
false
;
$method_is_abstract
=
false
;
foreach
(
$attributes
as
$attribute
)
{
if
(
strtolower
(
$attribute
->
getConcreteString
(
)
)
===
'static'
)
{
$method_is_static
=
true
;
}
if
(
strtolower
(
$attribute
->
getConcreteString
(
)
)
===
'abstract'
)
{
$method_is_abstract
=
true
;
}
}
if
(
$method_is_abstract
)
{
continue
;
}
if
(
!
$method_is_static
)
{
continue
;
}
$body
=
$method
->
getChildOfType
(
5
,
'n_STATEMENT_LIST'
)
;
$variables
=
$body
->
selectDescendantsOfType
(
'n_VARIABLE'
)
;
foreach
(
$variables
as
$variable
)
{
if
(
$method_is_static
&&
strtolower
(
$variable
->
getConcreteString
(
)
)
===
'$this'
)
{
$this
->
raiseLintAtNode
(
$variable
,
pht
(
'You can not reference `%s` inside a static method.'
,
'$this'
)
)
;
}
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Apr 17, 06:40 (3 d, 22 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1135545
Default Alt Text
ArcanistStaticThisXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment