Skip to content

Commit 8cc7f07

Browse files
ArshidArshid
authored andcommitted
OrdSingleByteRector
1 parent 3f3de0c commit 8cc7f07

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

rules-tests/Php85/Rector/FuncCall/OrdSingleByteRector/Fixture/multibyte-int.php.inc renamed to rules-tests/Php85/Rector/FuncCall/OrdSingleByteRector/Fixture/multibyte_int.php.inc

File renamed without changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
namespace Rector\Tests\Php85\Rector\FuncCall\OrdSingleByteRector\Fixture;
3+
$i = 123;
4+
echo ord($i);
5+
?>
6+
-----
7+
<?php
8+
namespace Rector\Tests\Php85\Rector\FuncCall\OrdSingleByteRector\Fixture;
9+
$i = 123;
10+
echo ord(1);
11+
?>

rules-tests/Php85/Rector/FuncCall/OrdSingleByteRector/Fixture/multibyte-str.php.inc renamed to rules-tests/Php85/Rector/FuncCall/OrdSingleByteRector/Fixture/multibyte_str.php.inc

File renamed without changes.

rules/Php85/Rector/FuncCall/OrdSingleByteRector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public function refactor(Node $node): ?Node
7070
}
7171

7272
$argExpr = $args[0]->value;
73+
$type = $this->nodeTypeResolver->getNativeType($argExpr);
74+
75+
if (! $type->isInteger()->yes() && ! $type->isString()->yes()) {
76+
return null;
77+
}
7378

7479
$value = $this->valueResolver->getValue($argExpr);
7580

@@ -93,4 +98,4 @@ public function provideMinPhpVersion(): int
9398
{
9499
return PhpVersionFeature::DEPRECATE_ORD_WITH_MULTIBYTE_STRING;
95100
}
96-
}
101+
}

0 commit comments

Comments
 (0)