Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1431700
ShortArrayPlugin.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
ShortArrayPlugin.php
View Options
<?php
declare
(
strict_types
=
1
);
use
ast\Node
;
use
Phan\Config
;
use
Phan\Issue
;
use
Phan\PluginV3
;
use
Phan\PluginV3\PluginAwarePostAnalysisVisitor
;
use
Phan\PluginV3\PostAnalyzeNodeCapability
;
/**
* Demo plugin to suggest using short array syntax.
*
* TODO: Implement a fixer if possible, e.g. base it on token_get_all()
*/
class
ShortArrayPlugin
extends
PluginV3
implements
PostAnalyzeNodeCapability
{
/**
* @return string - name of PluginAwarePostAnalysisVisitor subclass
* @override
*/
public
static
function
getPostAnalyzeNodeVisitorClassName
():
string
{
return
ShortArrayVisitor
::
class
;
}
}
/**
* This class has visitArray called on all array literals in files to suggest using short arrays instead
*/
class
ShortArrayVisitor
extends
PluginAwarePostAnalysisVisitor
{
// Do not define the visit() method unless a plugin has code and needs to visit most/all node types.
/**
* @param Node $node
* An array literal(AST_ARRAY) node to analyze
* @override
*/
public
function
visitArray
(
Node
$node
):
void
{
switch
(
$node
->
flags
)
{
case
\ast\flags\ARRAY_SYNTAX_LONG
:
$this
->
emit
(
'PhanPluginShortArray'
,
'Should use [] instead of array()'
,
[],
Issue
::
SEVERITY_LOW
,
Issue
::
REMEDIATION_A
);
return
;
case
\ast\flags\ARRAY_SYNTAX_LIST
:
if
(
Config
::
get_closest_minimum_target_php_version_id
()
>=
70100
)
{
$this
->
emit
(
'PhanPluginShortArrayList'
,
'Should use [] instead of list()'
,
[],
Issue
::
SEVERITY_LOW
,
Issue
::
REMEDIATION_A
);
}
}
}
}
// Every plugin needs to return an instance of itself at the
// end of the file in which it's defined.
return
new
ShortArrayPlugin
();
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 20:58 (1 d, 12 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
57/c7/b608f0e7a61282e08117d2ea5514
Default Alt Text
ShortArrayPlugin.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment