Skip to content

Commit

Permalink
Forbid PHPUnitPHAR prefixed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 5, 2024
1 parent 677afdd commit 2856081
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Rules/ClassForbiddenNameCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ClassForbiddenNameCheck
'PHPStan' => '_PHPStan_',
'Rector' => 'RectorPrefix',
'PHP-Scoper' => '_PhpScoper',
'PHPUnit' => 'PHPUnitPHAR',
];

public function __construct(private Container $container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ public function testPhpstanInternalClass(): void
],
[
'Referencing prefixed Rector class: RectorPrefix202302\AClass.',
52,
56,
$tip,
],
[
'Referencing prefixed PHP-Scoper class: _PhpScoper19ae93be897e\AClass.',
55,
59,
$tip,
],
[
'Referencing prefixed PHPUnit class: PHPUnitPHAR\SebastianBergmann\Diff\Exception.',
62,
'This is most likely unintentional. Did you mean to type \SebastianBergmann\Diff\Exception?',
],
]);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Classes/data/phpstan-internal-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ class AClass {
const Test = 1;
}

namespace PHPUnitPHAR\SebastianBergmann\Diff; // mimicks a prefixed class, as contained in PHPUnit phar

class Exception{}

namespace TestPhpstanInternalClass2;

class FooBar extends \RectorPrefix202302\AClass
{}

class Baz extends \_PhpScoper19ae93be897e\AClass
{}

class BazBar extends \PHPUnitPHAR\SebastianBergmann\Diff\Exception
{}

0 comments on commit 2856081

Please sign in to comment.