Skip to content

Commit

Permalink
- partially move PHPStan to level6
Browse files Browse the repository at this point in the history
  • Loading branch information
vv12131415 committed Jan 24, 2021
1 parent 1dea724 commit 9957026
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\(\\)\\.$#"
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions src/Admin/FieldDescriptionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@
* @final since sonata-project/admin-bundle 3.52
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* @phpstan-template TValue of FieldDescriptionInterface
* @phpstan-implements \ArrayAccess<string,TValue>
*/
class FieldDescriptionCollection implements \ArrayAccess, \Countable
{
/**
* @var array<string, FieldDescriptionInterface>
*
* @phpstan-var array<string, TValue>
*/
protected $elements = [];

/**
* @phpstan-param TValue $fieldDescription
*/
public function add(FieldDescriptionInterface $fieldDescription)
{
$this->elements[$fieldDescription->getName()] = $fieldDescription;
}

/**
* @return array<string, FieldDescriptionInterface>
*
* @phpstan-return array<string, TValue>
*/
public function getElements()
{
Expand All @@ -54,6 +64,8 @@ public function has($name)
* @throws \InvalidArgumentException
*
* @return FieldDescriptionInterface
*
* @phpstan-return TValue
*/
public function get($name)
{
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Datagrid/SimplePager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
* @author Sjoerd Peters <sjoerd.peters@gmail.com>
*
* @phpstan-template T of ProxyQueryInterface
* @phpstan-extends Pager<T>
*/
class SimplePager extends Pager
{
Expand Down
1 change: 1 addition & 0 deletions src/Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down

0 comments on commit 9957026

Please sign in to comment.