Skip to content

Commit feecf76

Browse files
committed
[Php85] Skip single char literal string/int on OrdSingleByteRector
1 parent 0071144 commit feecf76

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\FuncCall\OrdSingleByteRector\Fixture;
4+
5+
final class SkipSingleLiteralInt
6+
{
7+
public function run()
8+
{
9+
return ord(0);
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\FuncCall\OrdSingleByteRector\Fixture;
4+
5+
final class SkipSingleLiteralString
6+
{
7+
public function run()
8+
{
9+
return ord('0');
10+
}
11+
}

rules/Php85/Rector/FuncCall/OrdSingleByteRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public function refactor(Node $node): ?Node
8383
$value = $this->valueResolver->getValue($argExpr);
8484
$isInt = is_int($value);
8585

86+
if ($argExpr instanceof String_ && strlen($argExpr->value) === 1){
87+
return null;
88+
}
89+
90+
if ($argExpr instanceof Int_ && strlen((string) $argExpr->value) === 1){
91+
return null;
92+
}
93+
8694
if (! $argExpr instanceof Int_) {
8795
return $this->refactorStringType($argExpr, $isInt, $args, $node);
8896
}

0 commit comments

Comments
 (0)