Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4130948
StaticVariableMisusePlugin.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
StaticVariableMisusePlugin.php
View Options
<?php
declare
(
strict_types
=
1
);
use
ast\Node
;
use
Phan\AST\ASTReverter
;
use
Phan\Issue
;
use
Phan\PluginV3
;
use
Phan\PluginV3\PluginAwarePostAnalysisVisitor
;
use
Phan\PluginV3\PostAnalyzeNodeCapability
;
/**
* NOTE: This is automatically loaded by phan. Do not include it in a config.
*
* Checks for potentially misusing static variables
*/
final
class
StaticVariableMisusePlugin
extends
PluginV3
implements
PostAnalyzeNodeCapability
{
/**
* @return string - name of PluginAwarePostAnalysisVisitor subclass
*/
public
static
function
getPostAnalyzeNodeVisitorClassName
():
string
{
return
StaticVariableMisuseVisitor
::
class
;
}
}
/**
* Checks node kinds that can be used to access the inherited class
* for conflicts with uses of static variables.
*/
final
class
StaticVariableMisuseVisitor
extends
PluginAwarePostAnalysisVisitor
{
/**
* @override
*/
public
function
visitVar
(
Node
$node
):
void
{
$name
=
$node
->
children
[
'name'
];
if
(
$name
!==
'this'
)
{
return
;
}
$this
->
analyzeStaticAccessCommon
(
$node
);
}
/**
* @override
*/
public
function
visitName
(
Node
$node
):
void
{
$context
=
$this
->
context
;
if
(!
$context
->
isInClassScope
()
||
!
$context
->
isInFunctionLikeScope
())
{
return
;
}
$name
=
$node
->
children
[
'name'
];
if
(!
is_string
(
$name
))
{
return
;
}
if
(
strcasecmp
(
$name
,
'static'
)
!==
0
)
{
return
;
}
$this
->
analyzeStaticAccessCommon
(
$node
);
}
private
function
analyzeStaticAccessCommon
(
Node
$node
):
void
{
$context
=
$this
->
context
;
if
(!
$context
->
isInClassScope
()
||
!
$context
->
isInFunctionLikeScope
())
{
return
;
}
$function
=
$context
->
getFunctionLikeInScope
(
$this
->
code_base
);
if
(!
$function
->
hasStaticVariable
())
{
return
;
}
$class
=
$context
->
getClassInScope
(
$this
->
code_base
);
if
(
$class
->
isFinal
())
{
return
;
}
$this
->
emitIssue
(
Issue
::
StaticClassAccessWithStaticVariable
,
$node
->
lineno
,
ASTReverter
::
toShortString
(
$node
)
);
}
}
return
new
StaticVariableMisusePlugin
();
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 10:39 (2 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0d/35/510a921e0cde7f0e5c23361a5574
Default Alt Text
StaticVariableMisusePlugin.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment