Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889095
ArcanistControlStatementSpacingXHPASTLinterRule.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
ArcanistControlStatementSpacingXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistControlStatementSpacingXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
26
;
public
function
getLintName
(
)
{
return
pht
(
'Space After Control Statement'
)
;
}
public
function
getLintSeverity
(
)
{
return
ArcanistLintSeverity
::
SEVERITY_WARNING
;
}
public
function
process
(
XHPASTNode
$root
)
{
foreach
(
$root
->
getTokens
(
)
as
$id
=>
$token
)
{
switch
(
$token
->
getTypeName
(
)
)
{
case
'T_IF'
:
case
'T_ELSE'
:
case
'T_FOR'
:
case
'T_FOREACH'
:
case
'T_WHILE'
:
case
'T_DO'
:
case
'T_SWITCH'
:
case
'T_CATCH'
:
$after
=
$token
->
getNonsemanticTokensAfter
(
)
;
if
(
empty
(
$after
)
)
{
$this
->
raiseLintAtToken
(
$token
,
pht
(
'Convention: put a space after control statements.'
)
,
$token
->
getValue
(
)
.
' '
)
;
}
else
if
(
count
(
$after
)
===
1
)
{
$space
=
head
(
$after
)
;
// If we have an else clause with braces, $space may not be
// a single white space. e.g.,
//
// if ($x)
// echo 'foo'
// else // <- $space is not " " but "\n ".
// echo 'bar'
//
// We just require it starts with either a whitespace or a newline.
if
(
$token
->
getTypeName
(
)
===
'T_ELSE'
||
$token
->
getTypeName
(
)
===
'T_DO'
)
{
break
;
}
if
(
$space
->
isAnyWhitespace
(
)
&&
$space
->
getValue
(
)
!==
' '
)
{
$this
->
raiseLintAtToken
(
$space
,
pht
(
'Convention: put a single space after control statements.'
)
,
' '
)
;
}
}
break
;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Jan 19 2025, 11:23 (5 w, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1116180
Default Alt Text
ArcanistControlStatementSpacingXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment