Skip to content

Commit

Permalink
Fix some findings reported by PHPStan level 6
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Sep 3, 2023
1 parent 5502bae commit b4433e8
Show file tree
Hide file tree
Showing 44 changed files with 218 additions and 175 deletions.
17 changes: 1 addition & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ parameters:
path: src/Loggable/LoggableListener.php

-
message: "#^Method Gedmo\\\\Tool\\\\WrapperInterface\\<Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\>\\:\\:getIdentifier\\(\\) invoked with 2 parameters, 0-1 required\\.#"
message: "#^Method Gedmo\\\\Tool\\\\WrapperInterface\\<Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\>\\:\\:getIdentifier\\(\\) invoked with 2 parameters, 0\\-1 required\\.$#"
count: 2
path: src/Loggable/LoggableListener.php

Expand Down Expand Up @@ -360,21 +360,11 @@ parameters:
count: 1
path: src/Timestampable/Mapping/Driver/Yaml.php

-
message: "#^PHPDoc tag \\@param references unknown parameter\\: \\$flatten$#"
count: 1
path: src/Tool/WrapperInterface.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
count: 1
path: src/Tool/Wrapper/EntityWrapper.php

-
message: "#^Method Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper\\:\\:getIdentifier\\(\\) has parameter \\$flatten with no type specified\\.$#"
count: 1
path: src/Tool/Wrapper/EntityWrapper.php

-
message: "#^Parameter \\#2 \\$em of class Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper constructor expects Doctrine\\\\ORM\\\\EntityManagerInterface, Doctrine\\\\Persistence\\\\ObjectManager given\\.$#"
count: 1
Expand All @@ -390,11 +380,6 @@ parameters:
count: 2
path: src/Tool/Wrapper/MongoDocumentWrapper.php

-
message: "#^Method Gedmo\\\\Tool\\\\Wrapper\\\\MongoDocumentWrapper\\:\\:getIdentifier\\(\\) has parameter \\$flatten with no type specified\\.$#"
count: 1
path: src/Tool/Wrapper/MongoDocumentWrapper.php

-
message: "#^Access to offset 'association' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\FieldMapping\\.$#"
count: 2
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 5
level: 6
paths:
- src
- tests
Expand All @@ -13,10 +13,15 @@ parameters:
treatPhpDocTypesAsCertain: false
checkMissingVarTagTypehint: true
checkMissingTypehints: true
# @todo: Remove the "checkGenericClassInNonGenericObjectType" definition.
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
# @todo: Remove the following ignored error when the parameters are correctly declared.
- '#^Method Gedmo\\[^:]+::[^\(]+\(\) has parameter \$\w+ with no value type specified in iterable type array\.$#'

rules:
- PHPStan\Rules\Constants\MissingClassConstantTypehintRule
- PHPStan\Rules\Functions\MissingFunctionParameterTypehintRule
Expand Down
36 changes: 1 addition & 35 deletions src/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract class AbstractLogEntry implements LogEntryInterface
protected $version;

/**
* @var array|null
* @var array<string, mixed>|null
*
* @ORM\Column(type="array", nullable=true)
*/
Expand All @@ -108,8 +108,6 @@ public function getId()

/**
* Get action
*
* @return string|null
*/
public function getAction()
{
Expand All @@ -118,10 +116,6 @@ public function getAction()

/**
* Set action
*
* @param string $action
*
* @return void
*/
public function setAction($action)
{
Expand All @@ -130,8 +124,6 @@ public function setAction($action)

/**
* Get object class
*
* @return string|null
*/
public function getObjectClass()
{
Expand All @@ -140,10 +132,6 @@ public function getObjectClass()

/**
* Set object class
*
* @param string $objectClass
*
* @return void
*/
public function setObjectClass($objectClass)
{
Expand All @@ -152,8 +140,6 @@ public function setObjectClass($objectClass)

/**
* Get object id
*
* @return string|null
*/
public function getObjectId()
{
Expand All @@ -164,8 +150,6 @@ public function getObjectId()
* Set object id
*
* @param string $objectId
*
* @return void
*/
public function setObjectId($objectId)
{
Expand All @@ -174,8 +158,6 @@ public function setObjectId($objectId)

/**
* Get username
*
* @return string|null
*/
public function getUsername()
{
Expand All @@ -186,8 +168,6 @@ public function getUsername()
* Set username
*
* @param string $username
*
* @return void
*/
public function setUsername($username)
{
Expand All @@ -196,8 +176,6 @@ public function setUsername($username)

/**
* Get loggedAt
*
* @return \DateTime|null
*/
public function getLoggedAt()
{
Expand All @@ -206,8 +184,6 @@ public function getLoggedAt()

/**
* Set loggedAt to "now"
*
* @return void
*/
public function setLoggedAt()
{
Expand All @@ -216,8 +192,6 @@ public function setLoggedAt()

/**
* Get data
*
* @return array|null
*/
public function getData()
{
Expand All @@ -226,10 +200,6 @@ public function getData()

/**
* Set data
*
* @param array $data
*
* @return void
*/
public function setData($data)
{
Expand All @@ -240,8 +210,6 @@ public function setData($data)
* Set current version
*
* @param int $version
*
* @return void
*/
public function setVersion($version)
{
Expand All @@ -250,8 +218,6 @@ public function setVersion($version)

/**
* Get current version
*
* @return int|null
*/
public function getVersion()
{
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Driver
* Read the extended metadata configuration for a single mapped class.
*
* @param ClassMetadata&(OdmClassMetadata|OrmClassMetadata) $meta
* @param array<string, mixed> $config
*
* @return void
*
Expand Down
4 changes: 4 additions & 0 deletions src/Mapping/Driver/AbstractAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ protected function isValidField($meta, $field)
* @param string $name the related object class name
*
* @return string related class name or empty string if does not exist
*
* @phpstan-param class-string|string $name
*
* @phpstan-return class-string|''
*/
protected function getRelatedClassName($metadata, $name)
{
Expand Down
12 changes: 10 additions & 2 deletions src/Mapping/Driver/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public function setOriginalDriver($driver)
*
* @param string $file the mapping file to load
*
* @return array
* @return array<string, array<string, mixed>|object|null>
*
* @phpstan-return array<class-string, array<string, mixed>|object|null>
*/
abstract protected function _loadMappingFile($file);

Expand All @@ -112,7 +114,9 @@ abstract protected function _loadMappingFile($file);
*
* @param string $className
*
* @return array|object|null
* @return array<string, mixed>|object|null
*
* @phpstan-param class-string $className
*/
protected function _getMapping($className)
{
Expand Down Expand Up @@ -140,6 +144,10 @@ protected function _getMapping($className)
* @param string $name the related object class name
*
* @return string related class name or empty string if does not exist
*
* @phpstan-param class-string|string $name
*
* @phpstan-return class-string|''
*/
protected function getRelatedClassName($metadata, $name)
{
Expand Down
10 changes: 6 additions & 4 deletions src/Mapping/Event/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function getObjectState($uow, $object);
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
* @param object $object
*
* @return array
* @return array<string, array<int, mixed>|object>
*
* @phpstan-return array<string, array{0: mixed, 1: mixed}|object>
*/
public function getObjectChangeSet($uow, $object);

Expand Down Expand Up @@ -123,7 +125,7 @@ public function recomputeSingleObjectChangeSet($uow, $meta, $object);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectUpdates($uow);

Expand All @@ -132,7 +134,7 @@ public function getScheduledObjectUpdates($uow);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectInsertions($uow);

Expand All @@ -141,7 +143,7 @@ public function getScheduledObjectInsertions($uow);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectDeletions($uow);

Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/ExtensionMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(ObjectManager $objectManager, string $extensionNames
*
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata) $meta
*
* @return array the metatada configuration
* @return array<string, mixed> the metatada configuration
*/
public function getExtensionMetadata($meta)
{
Expand Down
4 changes: 3 additions & 1 deletion src/ReferenceIntegrity/Mapping/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class Validator
/**
* Returns a list of available integrity actions
*
* @return array
* @return string[]
*
* @phpstan-return array<int, self::NULLIFY|self::PULL|self::RESTRICT>
*/
public function getIntegrityActions()
{
Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Event/ReferencesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ReferencesAdapter extends AdapterInterface
* @param object $object
* @param bool $single
*
* @return array|string|int|null array or single identifier
* @return array<int|string, mixed>|string|int|null array or single identifier
*/
public function getIdentifier($om, $object, $single = true);

Expand All @@ -52,7 +52,7 @@ public function getSingleReference($om, $class, $identifier);
* @param object $object
* @param bool $single
*
* @return array|string|int|null array or single identifier
* @return array<int|string, mixed>|string|int|null array or single identifier
*/
public function extractIdentifier($om, $object, $single = true);
}
2 changes: 1 addition & 1 deletion src/Sluggable/Mapping/Event/SluggableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface SluggableAdapter extends AdapterInterface
* @param string $slug
* @phpstan-param SluggableConfiguration $config
*
* @return array
* @return array<int, array<string, mixed>>
*/
public function getSimilarSlugs($object, $meta, array $config, $slug);

Expand Down
6 changes: 4 additions & 2 deletions src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class SoftDeleteableFilter extends BsonFilter
/**
* Gets the criteria part to add to a query.
*
* @return array The criteria array, if there is available, empty array otherwise
* @return array<string, array<int, array<string, array<string, \DateTime>|null>>|null> The criteria array, if there is available, empty array otherwise
*
* @phpstan-return array<string, array<int, array<string, array{'$gt': \DateTime}|null>>|null>
*/
public function addFilterCriteria(ClassMetadata $targetEntity): array
{
Expand Down Expand Up @@ -96,7 +98,7 @@ public function enableForDocument($class)
}

/**
* @return SoftDeleteableListener|null
* @return SoftDeleteableListener
*/
protected function getListener()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sortable/Entity/Repository/SortableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getBySortableGroupsQueryBuilder(array $groupValues = [])
}

/**
* @return array
* @return array<int, object>
*/
public function getBySortableGroups(array $groupValues = [])
{
Expand Down
3 changes: 3 additions & 0 deletions src/Sortable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ protected function isValidField($meta, $field)
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
}

/**
* @param iterable<string, array<string, mixed>> $mapping
*/
private function readSortableGroups(iterable $mapping, array &$config): void
{
foreach ($mapping as $field => $fieldMapping) {
Expand Down
3 changes: 3 additions & 0 deletions src/Sortable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function updatePositions($relocation, $delta, $config)
$q->getSingleScalarResult();
}

/**
* @param iterable<string, mixed> $groups
*/
private function addGroupWhere(QueryBuilder $qb, ClassMetadata $metadata, iterable $groups): void
{
$i = 1;
Expand Down
Loading

0 comments on commit b4433e8

Please sign in to comment.