Skip to content

Commit d505a16

Browse files
authored
@phpstan ignore next line replacements (#809)
* [Code] Reworked \mglaman\PHPStanDrupal\Drupal\ExtensionMap::keyByExtensionName * [HACK] Temporarily remove core_baseline test * [Code] Reworked \mglaman\PHPStanDrupal\Drupal\ExtensionMap::keyByExtensionName * [Code] State these @phpstan-ignore-next-line have to stay * [Code] Remov eBC for PHP-Parser 4.x. * [Code] Remove BC for PHP-Parser 4.x. * [Code] Go wild and add an explanation why we want to keep the @phpstan-ignore-next-line in these cases * [Code] More replacements * Revert "[HACK] Temporarily remove core_baseline test" This reverts commit e0b8115.
1 parent ce1e7a1 commit d505a16

9 files changed

+18
-23
lines changed

src/Drupal/ExtensionMap.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use function array_combine;
66
use function array_map;
7-
use function is_array;
87

98
final class ExtensionMap
109
{
@@ -74,14 +73,8 @@ public function setExtensions(array $modules, array $themes, array $profiles): v
7473
*/
7574
private static function keyByExtensionName(array $extensions): array
7675
{
77-
// PHP 7.4 returns array|false, PHP 8.0 only returns an array.
78-
// Make PHPStan happy. When PHP 7.4 is dropped, reduce to a single
79-
// return.
80-
$combined = array_combine(array_map(static function (Extension $extension) {
76+
return array_combine(array_map(static function (Extension $extension) {
8177
return $extension->getName();
8278
}, $extensions), $extensions);
83-
// @phpstan-ignore-next-line
84-
assert(is_array($combined));
85-
return $combined;
8679
}
8780
}

src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function processNode(Node $node, Scope $scope): array
4949
return [];
5050
}
5151

52+
// The next line is intentionally not using [at]phpstan-ignore [identifier].
53+
// The identifier would be 'class.notFound', which would not be true in
54+
// case of a D9 scan and thus would fail the 'phpstan analyze' phase.
5255
// @phpstan-ignore-next-line
5356
$cmfRouteObjectInterfaceType = new ObjectType(SymfonyRouteObjectInterface::class);
5457
if (!$classType->isSuperTypeOf($cmfRouteObjectInterfaceType)->yes()) {

src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function processNode(Node $node, Scope $scope): array
3939
}
4040
$method = $node->getMethodReflection();
4141

42+
// The next lines are intentionally not using [at]phpstan-ignore [identifier].
43+
// The identifier would be 'class.notFound', which would not be true in
44+
// case of a D9 scan and thus would fail the 'phpstan analyze' phase.
4245
// @phpstan-ignore-next-line
4346
$cmfRouteObjectInterfaceType = new ObjectType(RouteObjectInterface::class);
4447
// @phpstan-ignore-next-line

src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use function count;
1313
use function in_array;
1414
use function interface_exists;
15-
use function method_exists;
1615
use function substr_compare;
1716

1817
/**
@@ -46,8 +45,7 @@ public function processNode(Node $node, Scope $scope): array
4645

4746
// Do some cheap preflight tests to make sure the class is in a
4847
// namespace that makes sense to inspect.
49-
// @phpstan-ignore-next-line
50-
$parts = method_exists($node->namespacedName, 'getParts') ? $node->namespacedName->getParts() : $node->namespacedName->parts;
48+
$parts = $node->namespacedName->getParts();
5149
// The namespace is too short to be a test so skip inspection.
5250
if (count($parts) < 3) {
5351
return [];

src/Type/EntityQuery/EntityQueryType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function withAccessCheck(): self
2727
{
2828
// The constructor of ObjectType is under backward compatibility promise.
2929
// @see https://phpstan.org/developing-extensions/backward-compatibility-promise
30-
// @phpstan-ignore-next-line
30+
// @phpstan-ignore new.static
3131
$type = new static(
3232
$this->getClassName(),
3333
$this->getSubtractedType(),
@@ -40,7 +40,7 @@ public function withAccessCheck(): self
4040

4141
public function asCount(): self
4242
{
43-
// @phpstan-ignore-next-line
43+
// @phpstan-ignore new.static
4444
$type = new static(
4545
$this->getClassName(),
4646
$this->getSubtractedType(),

tests/src/DrushIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ final class DrushIntegrationTest extends DrupalRuleTestCase
99

1010
protected function getRule(): \PHPStan\Rules\Rule
1111
{
12-
// @phpstan-ignore-next-line
12+
// @phpstan-ignore phpstanApi.constructor
1313
return new CallToNonExistentFunctionRule(
1414
$this->createReflectionProvider(),
1515
true

tests/src/Reflection/EntityFieldMethodsViaMagicReflectionExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function dataHasMethod(): \Generator
4747

4848
// A content entity for sure does not have this method.
4949
yield 'Content entity: referencedEntities' => [
50-
// @phpstan-ignore-next-line
50+
// @phpstan-ignore class.notFound
5151
EntityTest::class,
5252
'referencedEntities',
5353
false,

tests/src/Reflection/EntityFieldsViaMagicReflectionExtensionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public function testHasProperty(string $class, string $property, bool $result):
4343
public static function dataHasProperty(): \Generator
4444
{
4545
yield 'content entity supported' => [
46-
// @phpstan-ignore-next-line
46+
// @phpstan-ignore class.notFound
4747
EntityTest::class,
4848
'foobar',
4949
true
5050
];
5151
yield 'config entity not supported' => [
52-
// @phpstan-ignore-next-line
52+
// @phpstan-ignore class.notFound
5353
TestConfigType::class,
5454
'foobar',
5555
false
5656
];
5757
yield 'annotated properties are skipped on content entities' => [
58-
// @phpstan-ignore-next-line
58+
// @phpstan-ignore class.notFound
5959
ReflectionEntityTest::class,
6060
'user_id',
6161
false
@@ -92,7 +92,7 @@ public static function dataHasProperty(): \Generator
9292

9393
public function testGetPropertyEntity(): void
9494
{
95-
// @phpstan-ignore-next-line
95+
// @phpstan-ignore class.notFound
9696
$classReflection = $this->createReflectionProvider()->getClass(EntityTest::class);
9797
$propertyReflection = $this->extension->getProperty($classReflection, 'field_myfield');
9898
$readableType = $propertyReflection->getReadableType();

tests/src/Rules/AccessCheckImpossibleTypeCallRuleTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ final class AccessCheckImpossibleTypeCallRuleTest extends DrupalRuleTestCase
1414

1515
protected function getRule(): Rule
1616
{
17-
// @phpstan-ignore-next-line
17+
// @phpstan-ignore phpstanApi.constructor
1818
return new ImpossibleCheckTypeMethodCallRule(
19-
// @phpstan-ignore-next-line
19+
// @phpstan-ignore phpstanApi.constructor
2020
new ImpossibleCheckTypeHelper(
2121
$this->createReflectionProvider(),
2222
$this->getTypeSpecifier(),
2323
[],
2424
false,
25-
true,
2625
),
2726
true,
2827
false,
2928
false,
30-
false,
3129
);
3230
}
3331

0 commit comments

Comments
 (0)