Skip to content

Commit

Permalink
[Php81] Handle crash on Crypt() single arg on NullToStrictStringFuncC…
Browse files Browse the repository at this point in the history
…allArgRector (#2767)
  • Loading branch information
samsonasik committed Aug 15, 2022
1 parent 128cc91 commit 933eb13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

/**
* Crypt requires 2 args since php 5.6, when it only fill 1st arg, it will only change 1st arg
*
* Note: Filling 2nd arg will require different Rule to match the salt algorithm.
*/
final class CryptOneArg
{
public function run($subject)
{
crypt($subject);
}
}

?>
-----
<?php

namespace Rector\Tests\Php80\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

/**
* Crypt requires 2 args since php 5.6, when it only fill 1st arg, it will only change 1st arg
*
* Note: Filling 2nd arg will require different Rule to match the salt algorithm.
*/
final class CryptOneArg
{
public function run($subject)
{
crypt((string) $subject);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ private function processNullToStrictStringOnNodePosition(
array $args,
int|string $position
): ?FuncCall {
if (! isset($args[$position])) {
return null;
}

$argValue = $args[$position]->value;

if ($argValue instanceof ConstFetch && $this->valueResolver->isNull($argValue)) {
Expand All @@ -405,11 +409,7 @@ private function processNullToStrictStringOnNodePosition(
return null;
}

if (! $type instanceof MixedType) {
return null;
}

if ($argValue instanceof Encapsed) {
if (! $type instanceof MixedType || $argValue instanceof Encapsed) {
return null;
}

Expand Down

0 comments on commit 933eb13

Please sign in to comment.