Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@phpstan ignore next line replacements #809

Merged
merged 9 commits into from
Nov 19, 2024
9 changes: 1 addition & 8 deletions src/Drupal/ExtensionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use function array_combine;
use function array_map;
use function is_array;

final class ExtensionMap
{
Expand Down Expand Up @@ -74,14 +73,8 @@ public function setExtensions(array $modules, array $themes, array $profiles): v
*/
private static function keyByExtensionName(array $extensions): array
{
// PHP 7.4 returns array|false, PHP 8.0 only returns an array.
// Make PHPStan happy. When PHP 7.4 is dropped, reduce to a single
// return.
$combined = array_combine(array_map(static function (Extension $extension) {
return array_combine(array_map(static function (Extension $extension) {
return $extension->getName();
}, $extensions), $extensions);
// @phpstan-ignore-next-line
assert(is_array($combined));
return $combined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

// The next line is intentionally not using [at]phpstan-ignore [identifier].
// The identifier would be 'class.notFound', which would not be true in
// case of a D9 scan and thus would fail the 'phpstan analyze' phase.
// @phpstan-ignore-next-line
$cmfRouteObjectInterfaceType = new ObjectType(SymfonyRouteObjectInterface::class);
if (!$classType->isSuperTypeOf($cmfRouteObjectInterfaceType)->yes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function processNode(Node $node, Scope $scope): array
}
$method = $node->getMethodReflection();

// The next lines are intentionally not using [at]phpstan-ignore [identifier].
// The identifier would be 'class.notFound', which would not be true in
// case of a D9 scan and thus would fail the 'phpstan analyze' phase.
// @phpstan-ignore-next-line
$cmfRouteObjectInterfaceType = new ObjectType(RouteObjectInterface::class);
// @phpstan-ignore-next-line
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use function count;
use function in_array;
use function interface_exists;
use function method_exists;
use function substr_compare;

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

// Do some cheap preflight tests to make sure the class is in a
// namespace that makes sense to inspect.
// @phpstan-ignore-next-line
$parts = method_exists($node->namespacedName, 'getParts') ? $node->namespacedName->getParts() : $node->namespacedName->parts;
$parts = $node->namespacedName->getParts();
// The namespace is too short to be a test so skip inspection.
if (count($parts) < 3) {
return [];
Expand Down
4 changes: 2 additions & 2 deletions src/Type/EntityQuery/EntityQueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function withAccessCheck(): self
{
// The constructor of ObjectType is under backward compatibility promise.
// @see https://phpstan.org/developing-extensions/backward-compatibility-promise
// @phpstan-ignore-next-line
// @phpstan-ignore new.static
$type = new static(
$this->getClassName(),
$this->getSubtractedType(),
Expand All @@ -40,7 +40,7 @@ public function withAccessCheck(): self

public function asCount(): self
{
// @phpstan-ignore-next-line
// @phpstan-ignore new.static
$type = new static(
$this->getClassName(),
$this->getSubtractedType(),
Expand Down
2 changes: 1 addition & 1 deletion tests/src/DrushIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class DrushIntegrationTest extends DrupalRuleTestCase

protected function getRule(): \PHPStan\Rules\Rule
{
// @phpstan-ignore-next-line
// @phpstan-ignore phpstanApi.constructor
return new CallToNonExistentFunctionRule(
$this->createReflectionProvider(),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function dataHasMethod(): \Generator

// A content entity for sure does not have this method.
yield 'Content entity: referencedEntities' => [
// @phpstan-ignore-next-line
// @phpstan-ignore class.notFound
EntityTest::class,
'referencedEntities',
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ public function testHasProperty(string $class, string $property, bool $result):
public static function dataHasProperty(): \Generator
{
yield 'content entity supported' => [
// @phpstan-ignore-next-line
// @phpstan-ignore class.notFound
EntityTest::class,
'foobar',
true
];
yield 'config entity not supported' => [
// @phpstan-ignore-next-line
// @phpstan-ignore class.notFound
TestConfigType::class,
'foobar',
false
];
yield 'annotated properties are skipped on content entities' => [
// @phpstan-ignore-next-line
// @phpstan-ignore class.notFound
ReflectionEntityTest::class,
'user_id',
false
Expand Down Expand Up @@ -92,7 +92,7 @@ public static function dataHasProperty(): \Generator

public function testGetPropertyEntity(): void
{
// @phpstan-ignore-next-line
// @phpstan-ignore class.notFound
$classReflection = $this->createReflectionProvider()->getClass(EntityTest::class);
$propertyReflection = $this->extension->getProperty($classReflection, 'field_myfield');
$readableType = $propertyReflection->getReadableType();
Expand Down
6 changes: 2 additions & 4 deletions tests/src/Rules/AccessCheckImpossibleTypeCallRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ final class AccessCheckImpossibleTypeCallRuleTest extends DrupalRuleTestCase

protected function getRule(): Rule
{
// @phpstan-ignore-next-line
// @phpstan-ignore phpstanApi.constructor
return new ImpossibleCheckTypeMethodCallRule(
// @phpstan-ignore-next-line
// @phpstan-ignore phpstanApi.constructor
new ImpossibleCheckTypeHelper(
$this->createReflectionProvider(),
$this->getTypeSpecifier(),
[],
false,
true,
),
true,
false,
false,
false,
);
}

Expand Down
Loading