Skip to content

Commit

Permalink
Fix PHPStan findings about iterable parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys authored and franmomu committed Sep 4, 2023
1 parent e910b4d commit 2bd2690
Show file tree
Hide file tree
Showing 68 changed files with 301 additions and 148 deletions.
10 changes: 5 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ parameters:
count: 3
path: src/Sluggable/Handler/TreeSlugHandler.php

-
message: "#^Part \\$option \\(array\\{string, mixed\\}\\) of encapsed string cannot be cast to string\\.$#"
count: 1
path: src/Sluggable/Mapping/Driver/Annotation.php

-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
count: 1
Expand Down Expand Up @@ -505,6 +500,11 @@ parameters:
count: 1
path: src/Tree/TreeListener.php

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

-
message: "#^Method Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:getExtensionConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 2
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ parameters:
- '#^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
Expand Down
3 changes: 2 additions & 1 deletion src/Loggable/Document/Repository/LogEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public function revert($document, $version = 1)
/**
* Fills a documents versioned fields with data
*
* @param object $document
* @param object $document
* @param array<string, mixed> $data
*
* @return void
*
Expand Down
4 changes: 4 additions & 0 deletions src/Loggable/Mapping/Driver/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected function isMappingValid(ClassMetadata $meta, $field)
}

/**
* @param array<string, mixed> $config
*
* @return bool
*/
protected function isClassAnnotationInValid(ClassMetadata $meta, array &$config)
Expand All @@ -117,6 +119,8 @@ protected function isClassAnnotationInValid(ClassMetadata $meta, array &$config)

/**
* Searches properties of embedded object for versioned fields
*
* @param array<string, mixed> $config
*/
private function inspectEmbeddedForVersioned(string $field, array &$config, \Doctrine\ORM\Mapping\ClassMetadata $meta): void
{
Expand Down
2 changes: 2 additions & 0 deletions src/Loggable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public function readExtendedMetadata($meta, array &$config)

/**
* Searches mappings on element for versioned fields
*
* @param array<string, mixed> $config
*/
private function inspectElementForVersioned(\SimpleXMLElement $element, array &$config, ClassMetadata $meta): void
{
Expand Down
4 changes: 4 additions & 0 deletions src/Loggable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ protected function _loadMappingFile($file)
return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));
}

/**
* @param array<string, array<string, array<string, mixed>>> $mapping
* @param array<string, mixed> $config
*/
private function inspectEmbeddedForVersioned(string $field, array $mapping, array &$config): void
{
if (isset($mapping['fields'])) {
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/Annotation/Blameable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class Blameable implements GedmoAnnotation
public $value;

/**
* @param array<string, mixed> $data
* @param string|string[]|null $field
* @param mixed $value
*/
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/Annotation/IpTraceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class IpTraceable implements GedmoAnnotation
public $value;

/**
* @param array<string, mixed> $data
* @param string|string[]|null $field
* @param mixed $value
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/Annotation/Loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ final class Loggable implements GedmoAnnotation
public $logEntryClass;

/**
* @param array<string, mixed> $data
*
* @phpstan-param class-string<T>|null $logEntryClass
*/
public function __construct(array $data = [], ?string $logEntryClass = null)
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/Annotation/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ abstract class Reference implements GedmoAnnotation
public $inversedBy;

/**
* @param array<string, mixed> $data
*
* @phpstan-param class-string|null $class
*/
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/Annotation/ReferenceIntegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class ReferenceIntegrity implements GedmoAnnotation
public $value;

/**
* @param string|array|null $data
* @param string|array<string, mixed>|null $data
*/
public function __construct($data = [], ?string $value = null)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Mapping/Annotation/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ final class Slug implements GedmoAnnotation
public $dateFormat = 'Y-m-d-H:i';

/**
* @param string[] $fields
* @param SlugHandler[] $handlers
* @param array<string, mixed> $data
* @param string[] $fields
* @param SlugHandler[] $handlers
*/
public function __construct(
array $data = [],
Expand Down
7 changes: 5 additions & 2 deletions src/Mapping/Annotation/SlugHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ final class SlugHandler implements GedmoAnnotation
public $class = '';

/**
* @var array<SlugHandlerOption>|array<array{string, mixed}>
* @var array<SlugHandlerOption>|array<string, mixed>
*/
public $options = [];

/**
* @phpstan-param string|class-string<SlugHandlerInterface> $class
* @param array<string, mixed> $data
*
* @phpstan-param string|class-string<SlugHandlerInterface> $class
* @phpstan-param array<SlugHandlerOption>|array<string, mixed> $options
*/
public function __construct(
array $data = [],
Expand Down
3 changes: 2 additions & 1 deletion src/Mapping/Annotation/SlugHandlerOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class SlugHandlerOption implements GedmoAnnotation
public $value;

/**
* @param mixed $value
* @param array<string, mixed> $data
* @param mixed $value
*/
public function __construct(
array $data = [],
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/SoftDeleteable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class SoftDeleteable implements GedmoAnnotation
/** @var bool */
public $hardDelete = true;

/**
* @param array<string, mixed> $data
*/
public function __construct(array $data = [], string $fieldName = 'deletedAt', bool $timeAware = false, bool $hardDelete = true)
{
if ([] !== $data) {
Expand Down
5 changes: 3 additions & 2 deletions src/Mapping/Annotation/Timestampable.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ final class Timestampable implements GedmoAnnotation
public $value;

/**
* @param string|string[] $field
* @param mixed $value
* @param array<string, mixed> $data
* @param string|string[] $field
* @param mixed $value
*/
public function __construct(array $data = [], string $on = 'update', $field = null, $value = null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class Translatable implements GedmoAnnotation
/** @var bool|null */
public $fallback;

/**
* @param array<string, mixed> $data
*/
public function __construct(array $data = [], ?bool $fallback = null)
{
if ([] !== $data) {
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/TranslationEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ final class TranslationEntity implements GedmoAnnotation
*/
public $class;

/**
* @param array<string, mixed> $data
*/
public function __construct(array $data = [], string $class = '')
{
if ([] !== $data) {
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/Annotation/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ final class Tree implements GedmoAnnotation
public $identifierMethod;

/**
* @param array<string, mixed> $data
*
* @phpstan-param 'closure'|'materializedPath'|'nested'|null $type
*/
public function __construct(
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/Annotation/TreeClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class TreeClosure implements GedmoAnnotation
public $class;

/**
* @param array<string, mixed> $data
*
* @phpstan-param string|class-string<AbstractClosure> $class
*/
public function __construct(array $data = [], string $class = '')
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/TreeLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ final class TreeLevel implements GedmoAnnotation
*/
public $base = 0;

/**
* @param array<string, mixed> $data
*/
public function __construct(
array $data = [],
int $base = 0
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/TreePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ final class TreePath implements GedmoAnnotation
/** @var bool */
public $endsWithSeparator = true;

/**
* @param array<string, mixed> $data
*/
public function __construct(
array $data = [],
string $separator = ',',
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/TreeRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class TreeRoot implements GedmoAnnotation
/** @var string|null */
public $identifierMethod;

/**
* @param array<string, mixed> $data
*/
public function __construct(array $data = [], ?string $identifierMethod = null)
{
if ([] !== $data) {
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/Annotation/Uploadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ final class Uploadable implements GedmoAnnotation
*/
public $disallowedTypes = '';

/**
* @param array<string, mixed> $data
*/
public function __construct(
array $data = [],
bool $allowOverwrite = false,
Expand Down
4 changes: 3 additions & 1 deletion src/Mapping/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ interface Driver
/**
* Read the extended metadata configuration for a single mapped class.
*
* @param ClassMetadata&(OdmClassMetadata|OrmClassMetadata) $meta
* @param ClassMetadata $meta
* @param array<string, mixed> $config
*
* @return void
*
* @throws InvalidMappingException if the mapping configuration is invalid
*
* @phpstan-param ClassMetadata&(OdmClassMetadata|OrmClassMetadata) $meta
*/
public function readExtendedMetadata($meta, array &$config);

Expand Down
4 changes: 2 additions & 2 deletions src/Mapping/Event/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface AdapterInterface
*
* Calls a method on the event args object.
*
* @param string $method
* @param array $args
* @param string $method
* @param array<int, mixed> $args
*
* @return mixed
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Mapping/ExtensionMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ protected function getDriver($omDriver)
return $driver;
}

/**
* @param array<string, mixed> $config
*/
private function storeConfiguration(string $className, array $config): void
{
if (null === $this->cacheItemPool) {
Expand Down
6 changes: 3 additions & 3 deletions src/References/Mapping/Event/ReferencesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function getIdentifier($om, $object, $single = true);
/**
* Gets a single reference from the provided object manager for a class and identifier.
*
* @param ObjectManager $om
* @param string $class
* @param array|string|int $identifier
* @param ObjectManager $om
* @param string $class
* @param array<int|string, mixed>|string|int $identifier
*
* @phpstan-param class-string $class
*
Expand Down
19 changes: 12 additions & 7 deletions src/Sluggable/Handler/SlugHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public function __construct(SluggableListener $sluggable);
* Hook on slug handlers before the decision is made whether
* the slug needs to be recalculated.
*
* @param object $object
* @param string $slug
* @param bool $needToChangeSlug
* @param array<string, mixed> $config
* @param object $object
* @param string $slug
* @param bool $needToChangeSlug
*
* @return void
*/
Expand All @@ -43,8 +44,9 @@ public function onChangeDecision(SluggableAdapter $ea, array &$config, $object,
/**
* Hook on slug handlers called after the slug is built.
*
* @param object $object
* @param string $slug
* @param array<string, mixed> $config
* @param object $object
* @param string $slug
*
* @return void
*/
Expand All @@ -53,8 +55,9 @@ public function postSlugBuild(SluggableAdapter $ea, array &$config, $object, &$s
/**
* Hook for slug handlers called after the slug is completed.
*
* @param object $object
* @param string $slug
* @param array<string, mixed> $config
* @param object $object
* @param string $slug
*
* @return void
*/
Expand All @@ -68,6 +71,8 @@ public function handlesUrlization();
/**
* Validates the options for the handler.
*
* @param array<string, mixed> $options
*
* @throws InvalidMappingException if the configuration is invalid
*
* @return void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ interface SlugHandlerWithUniqueCallbackInterface extends SlugHandlerInterface
/**
* Hook for slug handlers called before it is made unique.
*
* @param object $object
* @param string $slug
* @param array<string, mixed> $config
* @param object $object
* @param string $slug
*
* @return void
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Sluggable/Mapping/Driver/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ protected function getSlugHandlers(\ReflectionProperty $property, Slug $slug, Cl
}

/**
* @param array<string, mixed> $config
*
* @return array<string, array<string, mixed>>
*/
private function retrieveSlug(ClassMetadata $meta, array &$config, \ReflectionProperty $property, ?string $fieldNamePrefix = null): array
Expand Down
3 changes: 3 additions & 0 deletions src/Sluggable/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected function isValidField($meta, $field)
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
}

/**
* @param array<string, mixed> $config
*/
private function buildFieldConfiguration(ClassMetadata $meta, string $field, \SimpleXMLElement $mapping, array &$config): void
{
/**
Expand Down
Loading

0 comments on commit 2bd2690

Please sign in to comment.