Page MenuHomePhorge

ArcanistHexadecimalNumericScalarCasingXHPASTLinterRule.php
No OneTemporary

ArcanistHexadecimalNumericScalarCasingXHPASTLinterRule.php

<?php
final class ArcanistHexadecimalNumericScalarCasingXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 127;
public function getLintName() {
return pht('Hexadecimal Integer Casing');
}
public function getLintSeverity() {
return ArcanistLintSeverity::SEVERITY_WARNING;
}
public function process(XHPASTNode $root) {
$hexadecimals = $this->getHexadecimalNumericScalars($root);
foreach ($hexadecimals as $hexadecimal) {
$value = substr($hexadecimal->getConcreteString(), 2);
if (!preg_match('/^0x[0-9A-F]+$/', $hexadecimal->getConcreteString())) {
$this->raiseLintAtNode(
$hexadecimal,
pht(
'For consistency, write hexadecimals integers '.
'in uppercase with a leading `%s`.',
'0x'),
'0x'.strtoupper($value));
}
}
}
private function getHexadecimalNumericScalars(XHPASTNode $root) {
$numeric_scalars = $root->selectDescendantsOfType('n_NUMERIC_SCALAR');
$hexadecimal_numeric_scalars = array();
foreach ($numeric_scalars as $numeric_scalar) {
$number = $numeric_scalar->getConcreteString();
if (preg_match('/^0x[0-9A-F]+$/i', $number)) {
$hexadecimal_numeric_scalars[] = $numeric_scalar;
}
}
return $hexadecimal_numeric_scalars;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Jan 19, 12:46 (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1121019
Default Alt Text
ArcanistHexadecimalNumericScalarCasingXHPASTLinterRule.php (1 KB)

Event Timeline