Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22415151
ArcanistBinaryNumericScalarCasingXHPASTLinterRule.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
ArcanistBinaryNumericScalarCasingXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistBinaryNumericScalarCasingXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
131
;
public
function
getLintName
()
{
return
pht
(
'Binary Integer Casing'
);
}
public
function
getLintSeverity
()
{
return
ArcanistLintSeverity
::
SEVERITY_WARNING
;
}
public
function
process
(
XHPASTNode
$root
)
{
$binaries
=
$this
->
getBinaryNumericScalars
(
$root
);
foreach
(
$binaries
as
$binary
)
{
$value
=
substr
(
$binary
->
getConcreteString
(),
2
);
if
(!
preg_match
(
'/^0b[01]+$/'
,
$binary
->
getConcreteString
()))
{
$this
->
raiseLintAtNode
(
$binary
,
pht
(
'For consistency, write binary integers with a leading `%s`.'
,
'0b'
),
'0b'
.
$value
);
}
}
}
private
function
getBinaryNumericScalars
(
XHPASTNode
$root
)
{
$numeric_scalars
=
$root
->
selectDescendantsOfType
(
'n_NUMERIC_SCALAR'
);
$binary_numeric_scalars
=
array
();
foreach
(
$numeric_scalars
as
$numeric_scalar
)
{
$number
=
$numeric_scalar
->
getConcreteString
();
if
(
preg_match
(
'/^0b[01]+$/i'
,
$number
))
{
$binary_numeric_scalars
[]
=
$numeric_scalar
;
}
}
return
$binary_numeric_scalars
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 28, 01:24 (14 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1209216
Default Alt Text
ArcanistBinaryNumericScalarCasingXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline