From 99570266bd4bfb16a7d8c8ffa3e548589e543578 Mon Sep 17 00:00:00 2001 From: Vladyslav Startsev <17382248+vladyslavstartsev@users.noreply.github.com> Date: Sun, 24 Jan 2021 02:48:12 +0200 Subject: [PATCH] - partially move PHPStan to level6 --- phpstan-baseline.neon | 18 ++++++++++++++++++ phpstan.neon.dist | 4 ++++ src/Admin/FieldDescriptionCollection.php | 19 +++++++++++++++++++ src/Datagrid/SimplePager.php | 3 +++ src/Twig/Extension/SonataAdminExtension.php | 1 + 5 files changed, 45 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e8bb93bc9d..d42755da67 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -217,6 +217,24 @@ parameters: count: 1 path: src/Datagrid/Pager.php + - + # will be fixed in v4. This class will be removed + message: "#^Class Sonata\\\\AdminBundle\\\\Admin\\\\Admin extends generic class Sonata\\\\AdminBundle\\\\Admin\\\\AbstractAdmin but does not specify its types\\: T$#" + count: 1 + path: src/Admin/Admin.php + + - + # will be fixed in v4. This class will be removed + message: "#^Class Sonata\\\\AdminBundle\\\\Admin\\\\AdminExtension extends generic class Sonata\\\\AdminBundle\\\\Admin\\\\AbstractAdminExtension but does not specify its types\\: T$#" + count: 1 + path: src/Admin/AdminExtension.php + + - + # will be fixed in v4. Iterator interface will be removed + message: "#^Class Sonata\\\\AdminBundle\\\\Datagrid\\\\Pager implements generic interface Iterator but does not specify its types\\: TKey, TValue$#" + count: 1 + path: src/Datagrid/Pager.php + # Symfony related errors - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:arrayNode\\(\\)\\.$#" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c42c331f0b..27d61d4f97 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -13,3 +13,7 @@ parameters: - .phpstan/stubs/MetadataInterface.file - .phpstan/stubs/Exporter.file - .phpstan/stubs/TextExtension.file + checkGenericClassInNonGenericObjectType: true + checkMissingIterableValueType: true + checkMissingVarTagTypehint: true + checkMissingTypehints: true diff --git a/src/Admin/FieldDescriptionCollection.php b/src/Admin/FieldDescriptionCollection.php index e10c9979d2..940ba49aa9 100644 --- a/src/Admin/FieldDescriptionCollection.php +++ b/src/Admin/FieldDescriptionCollection.php @@ -17,14 +17,22 @@ * @final since sonata-project/admin-bundle 3.52 * * @author Thomas Rabaix + * + * @phpstan-template TValue of FieldDescriptionInterface + * @phpstan-implements \ArrayAccess */ class FieldDescriptionCollection implements \ArrayAccess, \Countable { /** * @var array + * + * @phpstan-var array */ protected $elements = []; + /** + * @phpstan-param TValue $fieldDescription + */ public function add(FieldDescriptionInterface $fieldDescription) { $this->elements[$fieldDescription->getName()] = $fieldDescription; @@ -32,6 +40,8 @@ public function add(FieldDescriptionInterface $fieldDescription) /** * @return array + * + * @phpstan-return array */ public function getElements() { @@ -54,6 +64,8 @@ public function has($name) * @throws \InvalidArgumentException * * @return FieldDescriptionInterface + * + * @phpstan-return TValue */ public function get($name) { @@ -79,6 +91,13 @@ public function offsetExists($offset) return $this->has($offset); } + /** + * @param string $offset + * + * @return FieldDescriptionInterface + * + * @phpstan-return TValue + */ public function offsetGet($offset) { return $this->get($offset); diff --git a/src/Datagrid/SimplePager.php b/src/Datagrid/SimplePager.php index 4d9a1ed2e0..d3a987d240 100644 --- a/src/Datagrid/SimplePager.php +++ b/src/Datagrid/SimplePager.php @@ -20,6 +20,9 @@ * * @author Lukas Kahwe Smith * @author Sjoerd Peters + * + * @phpstan-template T of ProxyQueryInterface + * @phpstan-extends Pager */ class SimplePager extends Pager { diff --git a/src/Twig/Extension/SonataAdminExtension.php b/src/Twig/Extension/SonataAdminExtension.php index 510327018c..bf8eaef2e3 100644 --- a/src/Twig/Extension/SonataAdminExtension.php +++ b/src/Twig/Extension/SonataAdminExtension.php @@ -568,6 +568,7 @@ public function renderRelationElement($element, FieldDescriptionInterface $field public function getUrlSafeIdentifier($model, ?AdminInterface $admin = null) { if (null === $admin) { + /** @phpstan-var class-string $class */ $class = ClassUtils::getClass($model); if (!$this->pool->hasAdminByClass($class)) { throw new \InvalidArgumentException('You must pass an admin.');