Skip to content

Commit df9de66

Browse files
committed
skip nullable object
1 parent 6138870 commit df9de66

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\DowngradePhp82\Rector\FuncCall\DowngradeIteratorCountToArrayRector\Fixture;
4+
5+
final class SkipNullableTraversable
6+
{
7+
function test(?\Traversable $data)
8+
{
9+
$c = iterator_count($data);
10+
$v = iterator_to_array($data);
11+
}
12+
}

rules/DowngradePhp82/Rector/FuncCall/DowngradeIteratorCountToArrayRector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1919
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2020
use Webmozart\Assert\Assert;
21+
use PHPStan\Type\TypeCombinator;
2122

2223
/**
2324
* @changelog https://www.php.net/manual/en/migration82.other-changes.php#migration82.other-changes.functions.spl
@@ -123,6 +124,7 @@ private function shouldSkip(Type $type): bool
123124
return false;
124125
}
125126

127+
$type = TypeCombinator::removeNull($type);
126128
return $type->isObject()
127129
->yes();
128130
}

0 commit comments

Comments
 (0)