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 95f7c90 commit f272eae
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 56 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
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
5 changes: 4 additions & 1 deletion src/Tool/Wrapper/EntityWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EntityWrapper extends AbstractWrapper
/**
* Entity identifier
*
* @var array|null
* @var array<string, mixed>|null
*/
private $identifier;

Expand Down Expand Up @@ -78,6 +78,9 @@ public function getRootObjectName()
return $this->meta->rootEntityName;
}

/**
* @param bool $flatten
*/
public function getIdentifier($single = true, $flatten = false)
{
$flatten = 1 < \func_num_args() && true === func_get_arg(1);
Expand Down
7 changes: 6 additions & 1 deletion src/Tool/Wrapper/MongoDocumentWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MongoDocumentWrapper extends AbstractWrapper
/**
* Document identifier
*
* @var mixed
* @var string|null
*/
private $identifier;

Expand Down Expand Up @@ -76,6 +76,11 @@ public function hasValidIdentifier()
return (bool) $this->getIdentifier();
}

/**
* @param bool $flatten
*
* @return string
*/
public function getIdentifier($single = true, $flatten = false)
{
if (!$this->identifier) {
Expand Down
5 changes: 2 additions & 3 deletions src/Tool/WrapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ public function getMetadata();
* Get the object identifier, single or composite.
*
* @param bool $single
* @param bool $flatten
*
* @return array|mixed Array if a composite value, otherwise a single scalar
* @return array<string, mixed>|mixed Array if a composite value, otherwise a single scalar
*
* @todo Uncomment the second parameter for 4.0
*/
public function getIdentifier($single = true/* , $flatten = false */);
public function getIdentifier($single = true/* , bool $flatten = false */);

/**
* Get the root object class name.
Expand Down
3 changes: 3 additions & 0 deletions tests/Gedmo/Mapping/Annotation/AnnotationArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function testArguments(array $expected, string $class, array $args, ?stri
}
}

/**
* @phpstan-return iterable<string, array{0: array<string, string|null>, 1: class-string<Blameable>, 2: array<int, array<string, string>|string>, 3?: string}>
*/
public static function getGedmoAnnotations(): iterable
{
yield 'args_without_data' => [['on' => 'delete', 'field' => 'some'], Blameable::class, [[], 'delete', 'some']];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function testLoadFromDoctrineAnnotation(string $annotationProperty, $expe
static::assertSame($annotation->$annotationProperty, $expectedReturn);
}

/**
* @phpstan-return iterable<int, array{0: string, 1: class-string}>
*/
abstract public static function getValidParameters(): iterable;

abstract protected function getAnnotationClass(): string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function testLoadFromDoctrineAnnotation(string $annotationProperty, strin
static::assertSame($annotation->$annotationProperty, $expectedReturn);
}

/**
* @phpstan-return iterable<int, array{0: string, 1: string, 2: ?bool}>
*/
abstract public function getValidParameters(): iterable;

abstract protected function getAnnotationClass(): string;
Expand Down
3 changes: 3 additions & 0 deletions tests/Gedmo/Tree/NestedTreeRootRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public function testGetPathAsStringWithInvalidStringMethod($stringMethod): void
]);
}

/**
* @phpstan-return iterable<int, array{0: string|int|null}>
*/
public static function invalidStringMethods(): iterable
{
yield [null];
Expand Down

0 comments on commit f272eae

Please sign in to comment.