Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 23, 2024
1 parent 2767ab1 commit e1cf9c3
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/Rules/ClassForbiddenNameCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use function sprintf;
use function str_starts_with;
use function strpos;
use function substr;

class ClassForbiddenNameCheck
{
Expand Down Expand Up @@ -36,11 +38,16 @@ public function checkClassNames(array $pairs): array
continue;
}

$tip = sprintf(

Check failure on line 41 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, ubuntu-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.

Check failure on line 41 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.2, windows-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.
'This is most likely unintentional. Did you mean to type %s?',
substr($className, strpos($className, '\\')),

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, ubuntu-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Parameter #2 $offset of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.

Check failure on line 43 in src/Rules/ClassForbiddenNameCheck.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.3, windows-latest)

Parameter #2 $start of function substr expects int, int<0, max>|false given.
);

$errors[] = RuleErrorBuilder::message(sprintf(
'Internal %s Class cannot be referenced: %s.',
'Referencing prefixed %s class: %s.',
$projectName,
$className,
))->line($pair->getNode()->getLine())->build();
))->line($pair->getNode()->getLine())->tip($tip)->nonIgnorable()->build();
}

return $errors;
Expand Down
8 changes: 6 additions & 2 deletions src/Rules/ClassNameCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ public function checkClassNames(array $pairs, bool $checkClassCaseSensitivity =
$errors = [];

if ($checkClassCaseSensitivity) {
$errors += $this->classCaseSensitivityCheck->checkClassNames($pairs);
foreach ($this->classCaseSensitivityCheck->checkClassNames($pairs) as $error) {
$errors[] = $error;
}
}
foreach ($this->classForbiddenNameCheck->checkClassNames($pairs) as $error) {
$errors[] = $error;
}
$errors += $this->classForbiddenNameCheck->checkClassNames($pairs);

return $errors;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPStan/Rules/Classes/ClassConstantRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,14 @@ public function testClassConstFetchDefined(): void

public function testPhpstanInternalClass(): void
{
$tip = 'This is most likely unintentional. Did you mean to type \AClass?';

$this->phpVersion = PHP_VERSION_ID;
$this->analyse([__DIR__ . '/data/phpstan-internal-class.php'], [
[
'Internal PHPStan Class cannot be referenced: _PHPStan_156ee64ba\AClass.',
'Referencing prefixed PHPStan class: _PHPStan_156ee64ba\AClass.',
28,
$tip,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,23 @@ public function testEnums(): void

public function testPhpstanInternalClass(): void
{
$tip = 'This is most likely unintentional. Did you mean to type \AClass?';

$this->analyse([__DIR__ . '/data/phpstan-internal-class.php'], [
[
'Internal PHPStan Class cannot be referenced: _PHPStan_156ee64ba\AClass.',
'Referencing prefixed PHPStan class: _PHPStan_156ee64ba\AClass.',
34,
$tip,
],
[
'Internal Rector Class cannot be referenced: RectorPrefix202302\AClass.',
'Referencing prefixed Rector class: RectorPrefix202302\AClass.',
52,
$tip,
],
[
'Internal PHP-Scoper Class cannot be referenced: _PhpScoper19ae93be897e\AClass.',
'Referencing prefixed PHP-Scoper class: _PhpScoper19ae93be897e\AClass.',
55,
$tip,
],
]);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPStan/Rules/Classes/InstantiationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,13 @@ public function testBug10324(): void

public function testPhpstanInternalClass(): void
{
$tip = 'This is most likely unintentional. Did you mean to type \AClass?';

$this->analyse([__DIR__ . '/data/phpstan-internal-class.php'], [
[
'Internal PHPStan Class cannot be referenced: _PHPStan_156ee64ba\AClass.',
'Referencing prefixed PHPStan class: _PHPStan_156ee64ba\AClass.',
30,
$tip,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ public function testBug3690(): void

public function testPhpstanInternalClass(): void
{
$tip = 'This is most likely unintentional. Did you mean to type \PrefixedRuntimeException?';

$this->analyse([__DIR__ . '/../Classes/data/phpstan-internal-class.php'], [
[
'Internal PHPStan Class cannot be referenced: _PHPStan_156ee64ba\PrefixedRuntimeException.',
'Referencing prefixed PHPStan class: _PHPStan_156ee64ba\PrefixedRuntimeException.',
19,
$tip,
],
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ public function testRule(): void

public function testPhpstanInternalClass(): void
{
$tip = 'This is most likely unintentional. Did you mean to type \PrefixedRuntimeException?';

$this->analyse([__DIR__ . '/../Classes/data/phpstan-internal-class.php'], [
[
'Internal PHPStan Class cannot be referenced: _PHPStan_156ee64ba\PrefixedRuntimeException.',
'Referencing prefixed PHPStan class: _PHPStan_156ee64ba\PrefixedRuntimeException.',
14,
$tip,
],
]);
}
Expand Down

0 comments on commit e1cf9c3

Please sign in to comment.