Skip to content

Commit

Permalink
Skip Iterator in NoArrayAccessOnObjectRule
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 22, 2023
1 parent 71d5cee commit 2f6df68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/NoArrayAccessOnObjectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class NoArrayAccessOnObjectRule implements Rule, DocumentedRuleInterface
/**
* @var array<class-string>
*/
private const ALLOWED_CLASSES = ['SplFixedArray', 'SimpleXMLElement'];
private const ALLOWED_CLASSES = ['SplFixedArray', 'SimpleXMLElement', 'Iterator'];

public function __construct(
private readonly ArrayStringAndFnMatcher $arrayStringAndFnMatcher
Expand Down
15 changes: 15 additions & 0 deletions tests/Rules/NoArrayAccessOnObjectRule/Fixture/SkipIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\NoArrayAccessOnObjectRule\Fixture;

final class SkipIterator
{
public function run()
{
$iterator = new class extends \Iterator {};

return $iterator[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/ArrayAccessOnObject.php', [[NoArrayAccessOnObjectRule::ERROR_MESSAGE, 14]]];
yield [__DIR__ . '/Fixture/ArrayAccessOnNestedObject.php', [[NoArrayAccessOnObjectRule::ERROR_MESSAGE, 14]]];

yield [__DIR__ . '/Fixture/SkipIterator.php', []];
yield [__DIR__ . '/Fixture/SkipOnArray.php', []];
yield [__DIR__ . '/Fixture/SkipSplFixedArray.php', []];
yield [__DIR__ . '/Fixture/SkipXml.php', []];
Expand Down

0 comments on commit 2f6df68

Please sign in to comment.