Skip to content

Commit 4670e8f

Browse files
print raw value using shouldPrintRawValue
1 parent b4c065a commit 4670e8f

File tree

3 files changed

+5
-16
lines changed

3 files changed

+5
-16
lines changed

lib/PhpParser/Node/Scalar/Int_.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class Int_ extends Scalar {
1212
public const KIND_DEC = 10;
1313
public const KIND_HEX = 16;
1414

15-
public const KIND_RAW_VALUE = 22;
16-
1715
/** @var int Number value */
1816
public int $value;
1917

@@ -42,10 +40,6 @@ public function getSubNodeNames(): array {
4240
* @return Int_ The constructed LNumber, including kind attribute
4341
*/
4442
public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false): Int_ {
45-
if(isset($attributes['kind']) && $attributes['kind'] === self::KIND_RAW_VALUE){
46-
return new Int_((int) $str, $attributes);
47-
}
48-
4943
$attributes['rawValue'] = $str;
5044

5145
$str = str_replace('_', '', $str);

lib/PhpParser/PrettyPrinter/Standard.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ protected function pScalar_Int(Scalar\Int_ $node): string {
206206
$kind = $node->getAttribute('kind', Scalar\Int_::KIND_DEC);
207207

208208
if (Scalar\Int_::KIND_DEC === $kind) {
209-
return (string) $node->value;
209+
return $node->getAttribute('shouldPrintRawValue')
210+
? (string) $node->getAttribute('rawValue')
211+
: (string) $node->value;
210212
}
211213

212214
if ($node->value < 0) {
@@ -224,11 +226,6 @@ protected function pScalar_Int(Scalar\Int_ $node): string {
224226
case Scalar\Int_::KIND_HEX:
225227
return $sign . '0x' . base_convert($str, 10, 16);
226228
}
227-
228-
if (Scalar\Int_::KIND_RAW_VALUE === $kind) {
229-
return (string) $node->getAttribute('rawValue');
230-
}
231-
232229
throw new \Exception('Invalid number kind');
233230
}
234231

test/PhpParser/PrettyPrinterTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,8 @@ public function testInvalidIndent(): void {
308308

309309
public function testPrintCustomRawValue(): void {
310310
$prettyPrinter = new PrettyPrinter\Standard();
311-
$rawValue = '10_00';
312-
$attributes = ['rawValue' => $rawValue, 'kind' => Int_::KIND_RAW_VALUE];
311+
$node = new Int_(1000, ['rawValue' => '10_00', 'shouldPrintRawValue' => true]);
313312

314-
$this->assertSame($rawValue, $prettyPrinter->prettyPrintExpr(new Int_(1000, $attributes)));
315-
$this->assertSame($rawValue, $prettyPrinter->prettyPrintExpr(Int_::fromString('1000', $attributes)));
313+
$this->assertSame('10_00', $prettyPrinter->prettyPrintExpr($node));
316314
}
317315
}

0 commit comments

Comments
 (0)