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

Fix some findings from PHPStan level 6 #2686

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 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 Expand Up @@ -475,6 +460,11 @@ parameters:
count: 6
path: src/Tree/Mapping/Validator.php

-
message: "#^Method Gedmo\\\\Tree\\\\RepositoryUtils\\:\\:buildTreeArray\\(\\) should return array\\<int, array\\<string, mixed\\>\\> but returns array\\<int\\<0, max\\>, ArrayAccess\\>\\.$#"
count: 1
path: src/Tree/RepositoryUtils.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getFieldMapping\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -515,16 +505,31 @@ parameters:
count: 1
path: src/Tree/TreeListener.php

-
message: "#^Method Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:getExtensionConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 2
path: src/Uploadable/Event/UploadableBaseEventArgs.php

-
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$config is never read, only written\\.$#"
count: 1
path: src/Uploadable/Event/UploadableBaseEventArgs.php

-
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$config type has no value type specified in iterable type array\\.$#"
count: 2
path: src/Uploadable/Event/UploadableBaseEventArgs.php

-
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$extensionConfiguration is never written, only read\\.$#"
count: 1
path: src/Uploadable/Event/UploadableBaseEventArgs.php

-
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$extensionConfiguration type has no value type specified in iterable type array\\.$#"
count: 2
path: src/Uploadable/Event/UploadableBaseEventArgs.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
count: 1
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\.$#'
franmomu marked this conversation as resolved.
Show resolved Hide resolved

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
Loading
Loading