Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22421224
ArcanistDuplicateSwitchCaseXHPASTLinterRule.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
ArcanistDuplicateSwitchCaseXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistDuplicateSwitchCaseXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
50
;
public
function
getLintName
()
{
return
pht
(
'Duplicate Case Statements'
);
}
public
function
process
(
XHPASTNode
$root
)
{
$switch_statements
=
$root
->
selectDescendantsOfType
(
'n_SWITCH'
);
foreach
(
$switch_statements
as
$switch_statement
)
{
$case_statements
=
$switch_statement
->
getChildOfType
(
1
,
'n_STATEMENT_LIST'
)
->
getChildrenOfType
(
'n_CASE'
);
$nodes_by_case
=
array
();
foreach
(
$case_statements
as
$case_statement
)
{
$case
=
$case_statement
->
getChildByIndex
(
0
)
->
getSemanticString
();
$nodes_by_case
[
$case
][]
=
$case_statement
;
}
foreach
(
$nodes_by_case
as
$case
=>
$nodes
)
{
if
(
count
(
$nodes
)
<=
1
)
{
continue
;
}
$node
=
array_pop
(
$nodes_by_case
[
$case
]);
$message
=
$this
->
raiseLintAtNode
(
$node
,
pht
(
'Duplicate case in switch statement. PHP will ignore all '
.
'but the first case.'
));
$locations
=
array
();
foreach
(
$nodes_by_case
[
$case
]
as
$node
)
{
$locations
[]
=
$this
->
getOtherLocation
(
$node
->
getOffset
());
}
$message
->
setOtherLocations
(
$locations
);
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 28, 03:06 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1206066
Default Alt Text
ArcanistDuplicateSwitchCaseXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline