Skip to content

Commit a47b675

Browse files
phansysfranmomu
authored andcommitted
Fix some findings reported by PHPStan level 6
1 parent 1e430bf commit a47b675

File tree

44 files changed

+234
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+234
-171
lines changed

phpstan-baseline.neon

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ parameters:
6666
path: src/Loggable/LoggableListener.php
6767

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

@@ -360,21 +360,11 @@ parameters:
360360
count: 1
361361
path: src/Timestampable/Mapping/Driver/Yaml.php
362362

363-
-
364-
message: "#^PHPDoc tag \\@param references unknown parameter\\: \\$flatten$#"
365-
count: 1
366-
path: src/Tool/WrapperInterface.php
367-
368363
-
369364
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:getUnitOfWork\\(\\)\\.$#"
370365
count: 1
371366
path: src/Tool/Wrapper/EntityWrapper.php
372367

373-
-
374-
message: "#^Method Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper\\:\\:getIdentifier\\(\\) has parameter \\$flatten with no type specified\\.$#"
375-
count: 1
376-
path: src/Tool/Wrapper/EntityWrapper.php
377-
378368
-
379369
message: "#^Parameter \\#2 \\$em of class Gedmo\\\\Tool\\\\Wrapper\\\\EntityWrapper constructor expects Doctrine\\\\ORM\\\\EntityManagerInterface, Doctrine\\\\Persistence\\\\ObjectManager given\\.$#"
380370
count: 1
@@ -390,11 +380,6 @@ parameters:
390380
count: 2
391381
path: src/Tool/Wrapper/MongoDocumentWrapper.php
392382

393-
-
394-
message: "#^Method Gedmo\\\\Tool\\\\Wrapper\\\\MongoDocumentWrapper\\:\\:getIdentifier\\(\\) has parameter \\$flatten with no type specified\\.$#"
395-
count: 1
396-
path: src/Tool/Wrapper/MongoDocumentWrapper.php
397-
398383
-
399384
message: "#^Access to offset 'association' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\FieldMapping\\.$#"
400385
count: 2
@@ -475,6 +460,11 @@ parameters:
475460
count: 6
476461
path: src/Tree/Mapping/Validator.php
477462

463+
-
464+
message: "#^Method Gedmo\\\\Tree\\\\RepositoryUtils\\:\\:buildTreeArray\\(\\) should return array\\<int, array\\<string, mixed\\>\\> but returns array\\<int\\<0, max\\>, ArrayAccess\\>\\.$#"
465+
count: 1
466+
path: src/Tree/RepositoryUtils.php
467+
478468
-
479469
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getFieldMapping\\(\\)\\.$#"
480470
count: 2
@@ -515,16 +505,31 @@ parameters:
515505
count: 1
516506
path: src/Tree/TreeListener.php
517507

508+
-
509+
message: "#^Method Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:getExtensionConfiguration\\(\\) return type has no value type specified in iterable type array\\.$#"
510+
count: 2
511+
path: src/Uploadable/Event/UploadableBaseEventArgs.php
512+
518513
-
519514
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$config is never read, only written\\.$#"
520515
count: 1
521516
path: src/Uploadable/Event/UploadableBaseEventArgs.php
522517

518+
-
519+
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$config type has no value type specified in iterable type array\\.$#"
520+
count: 2
521+
path: src/Uploadable/Event/UploadableBaseEventArgs.php
522+
523523
-
524524
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$extensionConfiguration is never written, only read\\.$#"
525525
count: 1
526526
path: src/Uploadable/Event/UploadableBaseEventArgs.php
527527

528+
-
529+
message: "#^Property Gedmo\\\\Uploadable\\\\Event\\\\UploadableBaseEventArgs\\:\\:\\$extensionConfiguration type has no value type specified in iterable type array\\.$#"
530+
count: 2
531+
path: src/Uploadable/Event/UploadableBaseEventArgs.php
532+
528533
-
529534
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$isMappedSuperclass\\.$#"
530535
count: 1

phpstan.neon.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ includes:
44
- vendor/phpstan/phpstan-phpunit/extension.neon
55

66
parameters:
7-
level: 5
7+
level: 6
88
paths:
99
- src
1010
- tests
@@ -13,10 +13,15 @@ parameters:
1313
treatPhpDocTypesAsCertain: false
1414
checkMissingVarTagTypehint: true
1515
checkMissingTypehints: true
16+
# @todo: Remove the "checkGenericClassInNonGenericObjectType" definition.
17+
checkGenericClassInNonGenericObjectType: false
1618
ignoreErrors:
1719
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
1820
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
1921
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
22+
# @todo: Remove the following ignored error when the parameters are correctly declared.
23+
- '#^Method Gedmo\\[^:]+::[^\(]+\(\) has parameter \$\w+ with no value type specified in iterable type array\.$#'
24+
2025
rules:
2126
- PHPStan\Rules\Constants\MissingClassConstantTypehintRule
2227
- PHPStan\Rules\Functions\MissingFunctionParameterTypehintRule

src/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class AbstractLogEntry implements LogEntryInterface
8181
protected $version;
8282

8383
/**
84-
* @var array|null
84+
* @var array<string, mixed>|null
8585
*
8686
* @ORM\Column(type="array", nullable=true)
8787
*/
@@ -108,8 +108,6 @@ public function getId()
108108

109109
/**
110110
* Get action
111-
*
112-
* @return string|null
113111
*/
114112
public function getAction()
115113
{
@@ -118,10 +116,6 @@ public function getAction()
118116

119117
/**
120118
* Set action
121-
*
122-
* @param string $action
123-
*
124-
* @return void
125119
*/
126120
public function setAction($action)
127121
{
@@ -130,8 +124,6 @@ public function setAction($action)
130124

131125
/**
132126
* Get object class
133-
*
134-
* @return string|null
135127
*/
136128
public function getObjectClass()
137129
{
@@ -140,10 +132,6 @@ public function getObjectClass()
140132

141133
/**
142134
* Set object class
143-
*
144-
* @param string $objectClass
145-
*
146-
* @return void
147135
*/
148136
public function setObjectClass($objectClass)
149137
{
@@ -152,8 +140,6 @@ public function setObjectClass($objectClass)
152140

153141
/**
154142
* Get object id
155-
*
156-
* @return string|null
157143
*/
158144
public function getObjectId()
159145
{
@@ -164,8 +150,6 @@ public function getObjectId()
164150
* Set object id
165151
*
166152
* @param string $objectId
167-
*
168-
* @return void
169153
*/
170154
public function setObjectId($objectId)
171155
{
@@ -174,8 +158,6 @@ public function setObjectId($objectId)
174158

175159
/**
176160
* Get username
177-
*
178-
* @return string|null
179161
*/
180162
public function getUsername()
181163
{
@@ -186,8 +168,6 @@ public function getUsername()
186168
* Set username
187169
*
188170
* @param string $username
189-
*
190-
* @return void
191171
*/
192172
public function setUsername($username)
193173
{
@@ -196,8 +176,6 @@ public function setUsername($username)
196176

197177
/**
198178
* Get loggedAt
199-
*
200-
* @return \DateTime|null
201179
*/
202180
public function getLoggedAt()
203181
{
@@ -206,8 +184,6 @@ public function getLoggedAt()
206184

207185
/**
208186
* Set loggedAt to "now"
209-
*
210-
* @return void
211187
*/
212188
public function setLoggedAt()
213189
{
@@ -216,8 +192,6 @@ public function setLoggedAt()
216192

217193
/**
218194
* Get data
219-
*
220-
* @return array|null
221195
*/
222196
public function getData()
223197
{
@@ -226,10 +200,6 @@ public function getData()
226200

227201
/**
228202
* Set data
229-
*
230-
* @param array $data
231-
*
232-
* @return void
233203
*/
234204
public function setData($data)
235205
{
@@ -240,8 +210,6 @@ public function setData($data)
240210
* Set current version
241211
*
242212
* @param int $version
243-
*
244-
* @return void
245213
*/
246214
public function setVersion($version)
247215
{
@@ -250,8 +218,6 @@ public function setVersion($version)
250218

251219
/**
252220
* Get current version
253-
*
254-
* @return int|null
255221
*/
256222
public function getVersion()
257223
{

src/Mapping/Driver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface Driver
2727
* Read the extended metadata configuration for a single mapped class.
2828
*
2929
* @param ClassMetadata&(OdmClassMetadata|OrmClassMetadata) $meta
30+
* @param array<string, mixed> $config
3031
*
3132
* @return void
3233
*

src/Mapping/Driver/AbstractAnnotationDriver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ protected function isValidField($meta, $field)
116116
* @param string $name the related object class name
117117
*
118118
* @return string related class name or empty string if does not exist
119+
*
120+
* @phpstan-param class-string|string $name
121+
*
122+
* @phpstan-return class-string|''
119123
*/
120124
protected function getRelatedClassName($metadata, $name)
121125
{

src/Mapping/Driver/File.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public function setOriginalDriver($driver)
103103
*
104104
* @param string $file the mapping file to load
105105
*
106-
* @return array
106+
* @return array<string, array<string, mixed>|object|null>
107+
*
108+
* @phpstan-return array<class-string, array<string, mixed>|object|null>
107109
*/
108110
abstract protected function _loadMappingFile($file);
109111

@@ -112,7 +114,9 @@ abstract protected function _loadMappingFile($file);
112114
*
113115
* @param string $className
114116
*
115-
* @return array|object|null
117+
* @return array<string, mixed>|object|null
118+
*
119+
* @phpstan-param class-string $className
116120
*/
117121
protected function _getMapping($className)
118122
{
@@ -140,6 +144,10 @@ protected function _getMapping($className)
140144
* @param string $name the related object class name
141145
*
142146
* @return string related class name or empty string if does not exist
147+
*
148+
* @phpstan-param class-string|string $name
149+
*
150+
* @phpstan-return class-string|''
143151
*/
144152
protected function getRelatedClassName($metadata, $name)
145153
{

src/Mapping/Event/AdapterInterface.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ public function getObjectState($uow, $object);
9292
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
9393
* @param object $object
9494
*
95-
* @return array
95+
* @return array<string, array<int, mixed>|object>
96+
*
97+
* @phpstan-return array<string, array{0: mixed, 1: mixed}|object>
9698
*/
9799
public function getObjectChangeSet($uow, $object);
98100

@@ -123,7 +125,7 @@ public function recomputeSingleObjectChangeSet($uow, $meta, $object);
123125
*
124126
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
125127
*
126-
* @return array
128+
* @return array<int|string, object>
127129
*/
128130
public function getScheduledObjectUpdates($uow);
129131

@@ -132,7 +134,7 @@ public function getScheduledObjectUpdates($uow);
132134
*
133135
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
134136
*
135-
* @return array
137+
* @return array<int|string, object>
136138
*/
137139
public function getScheduledObjectInsertions($uow);
138140

@@ -141,7 +143,7 @@ public function getScheduledObjectInsertions($uow);
141143
*
142144
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
143145
*
144-
* @return array
146+
* @return array<int|string, object>
145147
*/
146148
public function getScheduledObjectDeletions($uow);
147149

src/Mapping/ExtensionMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct(ObjectManager $objectManager, string $extensionNames
100100
*
101101
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata) $meta
102102
*
103-
* @return array the metatada configuration
103+
* @return array<string, mixed> the metatada configuration
104104
*/
105105
public function getExtensionMetadata($meta)
106106
{

src/ReferenceIntegrity/Mapping/Validator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class Validator
3838
/**
3939
* Returns a list of available integrity actions
4040
*
41-
* @return array
41+
* @return string[]
42+
*
43+
* @phpstan-return array<int, self::NULLIFY|self::PULL|self::RESTRICT>
4244
*/
4345
public function getIntegrityActions()
4446
{

src/References/Mapping/Event/ReferencesAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ReferencesAdapter extends AdapterInterface
2828
* @param object $object
2929
* @param bool $single
3030
*
31-
* @return array|string|int|null array or single identifier
31+
* @return array<int|string, mixed>|string|int|null array or single identifier
3232
*/
3333
public function getIdentifier($om, $object, $single = true);
3434

@@ -52,7 +52,7 @@ public function getSingleReference($om, $class, $identifier);
5252
* @param object $object
5353
* @param bool $single
5454
*
55-
* @return array|string|int|null array or single identifier
55+
* @return array<int|string, mixed>|string|int|null array or single identifier
5656
*/
5757
public function extractIdentifier($om, $object, $single = true);
5858
}

0 commit comments

Comments
 (0)