Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22419942
ArcanistStaticThisXHPASTLinterRule.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
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
(
6
,
'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
Sat, Nov 28, 02:24 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223401
Default Alt Text
ArcanistStaticThisXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline