Skip to content

Commit 0f96c6f

Browse files
committed
Fix some PHPStan findings
1 parent a06dc64 commit 0f96c6f

File tree

24 files changed

+84
-135
lines changed

24 files changed

+84
-135
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"doctrine/orm": "^2.10.2",
5858
"friendsofphp/php-cs-fixer": "^3.4.0,<3.10",
5959
"nesbot/carbon": "^2.55",
60-
"phpstan/phpstan": "^1.1",
60+
"phpstan/phpstan": "^1.9",
6161
"phpstan/phpstan-doctrine": "^1.0",
6262
"phpstan/phpstan-phpunit": "^1.0",
6363
"phpunit/phpunit": "^8.5 || ^9.5",

phpstan-baseline.neon

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,6 @@ parameters:
110110
count: 1
111111
path: src/Mapping/Event/Adapter/ORM.php
112112

113-
-
114-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
115-
count: 1
116-
path: src/Mapping/ExtensionMetadataFactory.php
117-
118-
-
119-
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$reflClass\\.$#"
120-
count: 1
121-
path: src/Mapping/ExtensionMetadataFactory.php
122-
123113
-
124114
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\Driver\\\\MappingDriver\\:\\:getDefaultDriver\\(\\)\\.$#"
125115
count: 2
@@ -211,17 +201,17 @@ parameters:
211201
path: src/References/Mapping/Event/Adapter/ORM.php
212202

213203
-
214-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getReference\\(\\)\\.$#"
204+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
215205
count: 1
216206
path: src/References/Mapping/Event/Adapter/ORM.php
217207

218208
-
219-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
220-
count: 1
209+
message: "#^Call to method getClassMetadata\\(\\) on an unknown class Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManager\\.$#"
210+
count: 2
221211
path: src/References/Mapping/Event/Adapter/ORM.php
222212

223213
-
224-
message: "#^Call to method getClassMetadata\\(\\) on an unknown class Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManager\\.$#"
214+
message: "#^Call to method getReference\\(\\) on an unknown class Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManager\\.$#"
225215
count: 1
226216
path: src/References/Mapping/Event/Adapter/ORM.php
227217

@@ -230,11 +220,6 @@ parameters:
230220
count: 2
231221
path: src/References/Mapping/Event/Adapter/ORM.php
232222

233-
-
234-
message: "#^Parameter \\$dm of method Gedmo\\\\References\\\\Mapping\\\\Event\\\\Adapter\\\\ORM\\:\\:throwIfNotDocumentManager\\(\\) has invalid type Doctrine\\\\ODM\\\\PHPCR\\\\DocumentManager\\.$#"
235-
count: 1
236-
path: src/References/Mapping/Event/Adapter/ORM.php
237-
238223
-
239224
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:\\$reflClass\\.$#"
240225
count: 4
@@ -445,21 +430,6 @@ parameters:
445430
count: 2
446431
path: src/Tool/Wrapper/MongoDocumentWrapper.php
447432

448-
-
449-
message: "#^Right side of && is always true\\.$#"
450-
count: 2
451-
path: src/Translatable/Document/Repository/TranslationRepository.php
452-
453-
-
454-
message: "#^Negated boolean expression is always false\\.$#"
455-
count: 1
456-
path: src/Translatable/Entity/Repository/TranslationRepository.php
457-
458-
-
459-
message: "#^Right side of && is always true\\.$#"
460-
count: 2
461-
path: src/Translatable/Entity/Repository/TranslationRepository.php
462-
463433
-
464434
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
465435
count: 1
@@ -540,11 +510,6 @@ parameters:
540510
count: 2
541511
path: src/Tree/Entity/Repository/NestedTreeRepository.php
542512

543-
-
544-
message: "#^Negated boolean expression is always true\\.$#"
545-
count: 1
546-
path: src/Tree/Entity/Repository/NestedTreeRepository.php
547-
548513
-
549514
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
550515
count: 1
@@ -625,19 +590,9 @@ parameters:
625590
count: 1
626591
path: src/Uploadable/UploadableListener.php
627592

628-
-
629-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getConnection\\(\\)\\.$#"
630-
count: 1
631-
path: src/Uploadable/UploadableListener.php
632-
633-
-
634-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getEventManager\\(\\)\\.$#"
635-
count: 1
636-
path: src/Uploadable/UploadableListener.php
637-
638593
-
639594
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
640-
count: 4
595+
count: 3
641596
path: src/Uploadable/UploadableListener.php
642597

643598
-
@@ -695,11 +650,6 @@ parameters:
695650
count: 1
696651
path: tests/Gedmo/Timestampable/Fixture/ArticleCarbon.php
697652

698-
-
699-
message: "#^Strict comparison using \\=\\=\\= between null and Doctrine\\\\DBAL\\\\Platforms\\\\AbstractPlatform will always evaluate to false\\.$#"
700-
count: 1
701-
path: tests/Gedmo/Tool/BaseTestCaseORM.php
702-
703653
-
704654
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Gedmo\\\\\\\\Translatable\\\\\\\\Document\\\\\\\\Repository\\\\\\\\TranslationRepository' and Doctrine\\\\ORM\\\\EntityRepository\\<Gedmo\\\\Translatable\\\\Document\\\\Translation\\> will always evaluate to false\\.$#"
705655
count: 4

src/Loggable/Document/Repository/LogEntryRepository.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ public function revert($document, $version = 1)
8989
if ($logs instanceof Iterator) {
9090
$logs = $logs->toArray();
9191
}
92-
if ($logs) {
93-
$data = [];
94-
while ($log = array_shift($logs)) {
95-
$data = array_merge($data, $log->getData());
96-
}
97-
$this->fillDocument($document, $data);
98-
} else {
92+
93+
if ([] === $logs) {
9994
throw new \Gedmo\Exception\UnexpectedValueException('Count not find any log entries under version: '.$version);
10095
}
96+
97+
$data = [];
98+
while ($log = array_shift($logs)) {
99+
$data = array_merge($data, $log->getData());
100+
}
101+
$this->fillDocument($document, $data);
101102
}
102103

103104
/**

src/Loggable/Entity/Repository/LogEntryRepository.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,28 @@ public function revert($entity, $version = 1)
101101
$q->setParameters(compact('objectId', 'objectClass', 'version'));
102102
$logs = $q->getResult();
103103

104-
if ($logs) {
105-
$config = $this->getLoggableListener()->getConfiguration($this->_em, $objectMeta->getName());
106-
$fields = $config['versioned'];
107-
$filled = false;
108-
while (($log = array_pop($logs)) && !$filled) {
109-
if ($data = $log->getData()) {
110-
foreach ($data as $field => $value) {
111-
if (in_array($field, $fields, true)) {
112-
$this->mapValue($objectMeta, $field, $value);
113-
$wrapped->setPropertyValue($field, $value);
114-
unset($fields[array_search($field, $fields, true)]);
115-
}
104+
if ([] === $logs) {
105+
throw new \Gedmo\Exception\UnexpectedValueException('Could not find any log entries under version: '.$version);
106+
}
107+
108+
$config = $this->getLoggableListener()->getConfiguration($this->_em, $objectMeta->getName());
109+
$fields = $config['versioned'];
110+
$filled = false;
111+
while (($log = array_pop($logs)) && !$filled) {
112+
if ($data = $log->getData()) {
113+
foreach ($data as $field => $value) {
114+
if (in_array($field, $fields, true)) {
115+
$this->mapValue($objectMeta, $field, $value);
116+
$wrapped->setPropertyValue($field, $value);
117+
unset($fields[array_search($field, $fields, true)]);
116118
}
117119
}
118-
$filled = 0 === count($fields);
119120
}
120-
/*if (count($fields)) {
121-
throw new \Gedmo\Exception\UnexpectedValueException('Could not fully revert the entity to version: '.$version);
122-
}*/
123-
} else {
124-
throw new \Gedmo\Exception\UnexpectedValueException('Could not find any log entries under version: '.$version);
121+
$filled = [] === $fields;
125122
}
123+
/*if (count($fields)) {
124+
throw new \Gedmo\Exception\UnexpectedValueException('Could not fully revert the entity to version: '.$version);
125+
}*/
126126
}
127127

128128
/**

src/Loggable/LoggableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ protected function createLogEntry($action, $object, LoggableAdapter $ea)
319319
$logEntry->setData($newValues);
320320
}
321321

322-
if (LogEntryInterface::ACTION_UPDATE === $action && 0 === count($newValues)) {
322+
if (LogEntryInterface::ACTION_UPDATE === $action && [] === $newValues) {
323323
return null;
324324
}
325325

src/Mapping/ExtensionMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function __construct(ObjectManager $objectManager, string $extensionNames
9696
/**
9797
* Reads extension metadata
9898
*
99-
* @param ClassMetadata $meta
99+
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata) $meta
100100
*
101101
* @return array the metatada configuration
102102
*/

src/References/Mapping/Event/Adapter/ODM.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function getIdentifier($om, $object, $single = true)
5858

5959
public function getSingleReference($om, $class, $identifier)
6060
{
61-
$this->throwIfNotEntityManager($om);
6261
$meta = $om->getClassMetadata($class);
6362

6463
if (!$meta->isInheritanceTypeNone()) {
@@ -83,11 +82,4 @@ public function extractIdentifier($om, $object, $single = true)
8382

8483
return [$meta->getIdentifier()[0] => $id];
8584
}
86-
87-
/**
88-
* Override so we don't get an exception. We want to allow this.
89-
*/
90-
private function throwIfNotEntityManager(EntityManagerInterface $em): void
91-
{
92-
}
9385
}

src/References/Mapping/Event/Adapter/ORM.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public function extractIdentifier($om, $object, $single = true)
103103
/**
104104
* Override so we don't get an exception. We want to allow this.
105105
*
106-
* @param MongoDocumentManager|PhpcrDocumentManager $dm
106+
* @param mixed $dm
107+
*
108+
* @phpstan-assert MongoDocumentManager|PhpcrDocumentManager $dm
107109
*/
108110
private function throwIfNotDocumentManager($dm): void
109111
{

src/Sluggable/SluggableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private function generateSlug(SluggableAdapter $ea, object $object): void
306306
$config = $this->getConfiguration($om, $meta->getName());
307307

308308
foreach ($config['slugs'] as $slugField => $options) {
309-
$hasHandlers = count($options['handlers']);
309+
$hasHandlers = [] !== $options['handlers'];
310310
$options['useObjectClass'] = $config['useObjectClass'];
311311
// collect the slug from fields
312312
$slug = $meta->getReflectionProperty($slugField)->getValue($object);

src/Sortable/Entity/Repository/SortableRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getBySortableGroupsQueryBuilder(array $groupValues = [])
8383
}
8484
unset($groups[$name]);
8585
}
86-
if (count($groups) > 0) {
86+
if ([] !== $groups) {
8787
throw new \InvalidArgumentException('You need to specify values for the following groups to select by sortable groups: '.implode(', ', array_keys($groups)));
8888
}
8989

0 commit comments

Comments
 (0)