Skip to content

Commit 130c27c

Browse files
authored
Fix return types of cache interfaces (#9271)
1 parent 1e9973a commit 130c27c

File tree

11 files changed

+39
-130
lines changed

11 files changed

+39
-130
lines changed

lib/Doctrine/ORM/Cache/CollectionHydrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key
2828
* @param CollectionCacheEntry $entry The cached collection entry.
2929
* @param PersistentCollection $collection The collection to load the cache into.
3030
*
31-
* @return mixed[]
31+
* @return mixed[]|null
3232
*/
3333
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection);
3434
}

lib/Doctrine/ORM/Cache/ConcurrentRegion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ConcurrentRegion extends Region
1818
*
1919
* @param CacheKey $key The key of the item to lock.
2020
*
21-
* @return Lock A lock instance or NULL if the lock already exists.
21+
* @return Lock|null A lock instance or NULL if the lock already exists.
2222
*
2323
* @throws LockException Indicates a problem accessing the region.
2424
*/
@@ -30,7 +30,7 @@ public function lock(CacheKey $key);
3030
* @param CacheKey $key The key of the item to unlock.
3131
* @param Lock $lock The lock previously obtained from {@link readLock}
3232
*
33-
* @return void
33+
* @return bool
3434
*
3535
* @throws LockException Indicates a problem accessing the region.
3636
*/

lib/Doctrine/ORM/Cache/DefaultQueryCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DefaultQueryCache implements QueryCache
4545
/** @var QueryCacheValidator */
4646
private $validator;
4747

48-
/** @var CacheLogger */
48+
/** @var CacheLogger|null */
4949
protected $cacheLogger;
5050

5151
/** @var array<string,mixed> */

lib/Doctrine/ORM/Cache/EntityHydrator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e
2525
* @param EntityCacheKey $key The entity cache key.
2626
* @param EntityCacheEntry $entry The entity cache entry.
2727
* @param object $entity The entity to load the cache into. If not specified, a new entity is created.
28+
*
29+
* @return object|null
2830
*/
2931
public function loadCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, EntityCacheEntry $entry, $entity = null);
3032
}

lib/Doctrine/ORM/Cache/Region.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function get(CacheKey $key);
4545
* @param CacheEntry $entry The entry to cache.
4646
* @param Lock|null $lock The lock previously obtained.
4747
*
48+
* @return bool
49+
*
4850
* @throws CacheException Indicates a problem accessing the region.
4951
*/
5052
public function put(CacheKey $key, CacheEntry $entry, ?Lock $lock = null);
@@ -54,13 +56,17 @@ public function put(CacheKey $key, CacheEntry $entry, ?Lock $lock = null);
5456
*
5557
* @param CacheKey $key The key under which to cache the item.
5658
*
59+
* @return bool
60+
*
5761
* @throws CacheException Indicates a problem accessing the region.
5862
*/
5963
public function evict(CacheKey $key);
6064

6165
/**
6266
* Remove all contents of this particular cache region.
6367
*
68+
* @return bool
69+
*
6470
* @throws CacheException Indicates problem accessing the region.
6571
*/
6672
public function evictAll();

lib/Doctrine/ORM/Cache/Region/FileLockRegion.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ public function lock(CacheKey $key)
228228

229229
/**
230230
* {@inheritdoc}
231-
*
232-
* @return bool
233231
*/
234232
public function unlock(CacheKey $key, Lock $lock)
235233
{

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Method Doctrine\\\\ORM\\\\Cache\\\\DefaultCollectionHydrator\\:\\:loadCacheEntry\\(\\) should return array but returns null\\.$#"
5-
count: 1
6-
path: lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php
7-
83
-
94
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Persisters\\\\Entity\\\\EntityPersister\\:\\:getCacheRegion\\(\\)\\.$#"
105
count: 1
@@ -110,11 +105,6 @@ parameters:
110105
count: 1
111106
path: lib/Doctrine/ORM/Cache/Region/DefaultRegion.php
112107

113-
-
114-
message: "#^Method Doctrine\\\\ORM\\\\Cache\\\\Region\\\\FileLockRegion\\:\\:lock\\(\\) should return Doctrine\\\\ORM\\\\Cache\\\\Lock but returns null\\.$#"
115-
count: 2
116-
path: lib/Doctrine/ORM/Cache/Region/FileLockRegion.php
117-
118108
-
119109
message: "#^Access to an undefined property Doctrine\\\\ORM\\\\Cache\\\\CacheEntry\\:\\:\\$time\\.$#"
120110
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,7 @@
9090
<code>(string) $fileLockRegionDirectory</code>
9191
</RedundantCastGivenDocblockType>
9292
</file>
93-
<file src="lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php">
94-
<InvalidNullableReturnType occurrences="1">
95-
<code>loadCacheEntry</code>
96-
</InvalidNullableReturnType>
97-
<NullableReturnStatement occurrences="1">
98-
<code>null</code>
99-
</NullableReturnStatement>
100-
</file>
10193
<file src="lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php">
102-
<MissingReturnType occurrences="1">
103-
<code>loadCacheEntry</code>
104-
</MissingReturnType>
10594
<PossiblyUndefinedArrayOffset occurrences="1">
10695
<code>$fieldMapping['columnName']</code>
10796
</PossiblyUndefinedArrayOffset>
@@ -127,9 +116,6 @@
127116
<code>$assocEntry-&gt;class</code>
128117
<code>$assocEntry-&gt;class</code>
129118
</NoInterfaceProperties>
130-
<PossiblyNullPropertyAssignmentValue occurrences="1">
131-
<code>$cacheConfig-&gt;getCacheLogger()</code>
132-
</PossiblyNullPropertyAssignmentValue>
133119
<PossiblyNullReference occurrences="1">
134120
<code>getCacheLogger</code>
135121
</PossiblyNullReference>
@@ -149,11 +135,6 @@
149135
<code>$value-&gt;class</code>
150136
</ArgumentTypeCoercion>
151137
</file>
152-
<file src="lib/Doctrine/ORM/Cache/EntityHydrator.php">
153-
<MissingReturnType occurrences="1">
154-
<code>loadCacheEntry</code>
155-
</MissingReturnType>
156-
</file>
157138
<file src="lib/Doctrine/ORM/Cache/Logging/CacheLogger.php">
158139
<MissingReturnType occurrences="9">
159140
<code>collectionCacheHit</code>
@@ -304,13 +285,6 @@
304285
<code>lock</code>
305286
</UndefinedInterfaceMethod>
306287
</file>
307-
<file src="lib/Doctrine/ORM/Cache/Region.php">
308-
<MissingReturnType occurrences="3">
309-
<code>evict</code>
310-
<code>evictAll</code>
311-
<code>put</code>
312-
</MissingReturnType>
313-
</file>
314288
<file src="lib/Doctrine/ORM/Cache/Region/DefaultMultiGetRegion.php">
315289
<DeprecatedClass occurrences="2">
316290
<code>MultiGetCache</code>
@@ -339,23 +313,6 @@
339313
<code>(string) $name</code>
340314
</RedundantCastGivenDocblockType>
341315
</file>
342-
<file src="lib/Doctrine/ORM/Cache/Region/FileLockRegion.php">
343-
<ImplementedReturnTypeMismatch occurrences="1">
344-
<code>bool</code>
345-
</ImplementedReturnTypeMismatch>
346-
<InvalidNullableReturnType occurrences="1">
347-
<code>lock</code>
348-
</InvalidNullableReturnType>
349-
<MissingReturnType occurrences="3">
350-
<code>evict</code>
351-
<code>evictAll</code>
352-
<code>put</code>
353-
</MissingReturnType>
354-
<NullableReturnStatement occurrences="2">
355-
<code>null</code>
356-
<code>null</code>
357-
</NullableReturnStatement>
358-
</file>
359316
<file src="lib/Doctrine/ORM/Cache/Region/UpdateTimestampCache.php">
360317
<MissingReturnType occurrences="1">
361318
<code>update</code>

tests/Doctrine/Tests/Mocks/CacheRegionMock.php

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CacheRegionMock implements Region
2424
public $returns = [];
2525

2626
/** @var string */
27-
public $name;
27+
public $name = 'mock';
2828

2929
/**
3030
* Queue a return value for a specific method invocation
@@ -52,50 +52,35 @@ private function getReturn(string $method, $default)
5252
return $default;
5353
}
5454

55-
/**
56-
* {@inheritdoc}
57-
*/
58-
public function getName()
55+
public function getName(): string
5956
{
6057
$this->calls[__FUNCTION__][] = [];
6158

6259
return $this->name;
6360
}
6461

65-
/**
66-
* {@inheritdoc}
67-
*/
68-
public function contains(CacheKey $key)
62+
public function contains(CacheKey $key): bool
6963
{
7064
$this->calls[__FUNCTION__][] = ['key' => $key];
7165

7266
return $this->getReturn(__FUNCTION__, false);
7367
}
7468

75-
/**
76-
* {@inheritdoc}
77-
*/
78-
public function evict(CacheKey $key)
69+
public function evict(CacheKey $key): bool
7970
{
8071
$this->calls[__FUNCTION__][] = ['key' => $key];
8172

8273
return $this->getReturn(__FUNCTION__, true);
8374
}
8475

85-
/**
86-
* {@inheritdoc}
87-
*/
88-
public function evictAll()
76+
public function evictAll(): bool
8977
{
9078
$this->calls[__FUNCTION__][] = [];
9179

9280
return $this->getReturn(__FUNCTION__, true);
9381
}
9482

95-
/**
96-
* {@inheritdoc}
97-
*/
98-
public function get(CacheKey $key)
83+
public function get(CacheKey $key): ?CacheEntry
9984
{
10085
$this->calls[__FUNCTION__][] = ['key' => $key];
10186

@@ -105,17 +90,14 @@ public function get(CacheKey $key)
10590
/**
10691
* {@inheritdoc}
10792
*/
108-
public function getMultiple(CollectionCacheEntry $collection)
93+
public function getMultiple(CollectionCacheEntry $collection): ?array
10994
{
11095
$this->calls[__FUNCTION__][] = ['collection' => $collection];
11196

11297
return $this->getReturn(__FUNCTION__, null);
11398
}
11499

115-
/**
116-
* {@inheritdoc}
117-
*/
118-
public function put(CacheKey $key, CacheEntry $entry, ?Lock $lock = null)
100+
public function put(CacheKey $key, CacheEntry $entry, ?Lock $lock = null): bool
119101
{
120102
$this->calls[__FUNCTION__][] = ['key' => $key, 'entry' => $entry];
121103

0 commit comments

Comments
 (0)