Skip to content

Commit 80c47f7

Browse files
committed
Increased Phpstan validation up to level 6
1 parent 87af2ac commit 80c47f7

Some content is hidden

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

55 files changed

+228
-218
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: ./vendor/bin/phpmd lib/ ansi phpmd.xml
4242

4343
- name: Run PHPSTAN (lite)
44-
run: ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1
44+
run: ./vendor/bin/phpstan analyse lib/ -l 6 -c phpstan_lite.neon 2>&1
4545

4646
- name: Run TESTS
4747
env:

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ install:
5959
script:
6060
- ./vendor/bin/phpcs lib/ --report=summary
6161
- ./vendor/bin/phpmd lib/ ansi phpmd.xml
62-
- "[[ $TRAVIS_PHP_VERSION != \"nightly\" ]] && ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1"
62+
- "[[ $TRAVIS_PHP_VERSION != \"nightly\" ]] && ./vendor/bin/phpstan analyse lib/ -l 6 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1"
6363
- php -f ./bin/ci/run_tests.php

lib/Phpfastcache/Cluster/ClusterPoolTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function driverConnect(): bool
3333

3434
/**
3535
* @param ExtendedCacheItemInterface $item
36-
* @return ?array
36+
* @return ?array<string, mixed>
3737
*/
3838
protected function driverRead(ExtendedCacheItemInterface $item): ?array
3939
{

lib/Phpfastcache/Config/ConfigurationOption.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class ConfigurationOption extends AbstractConfigurationOption implements Configu
5050
protected ?object $superGlobalAccessor = null;
5151

5252
/**
53+
* @inheritDoc
5354
* @throws PhpfastcacheInvalidConfigurationException
5455
* @throws PhpfastcacheInvalidTypeException
5556
*/

lib/Phpfastcache/Config/ConfigurationOptionInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
interface ConfigurationOptionInterface extends LockableConfigurationInterface
2424
{
2525
/**
26+
* @param array<string, mixed> $parameters
2627
* ConfigurationOptionInterface constructor.
2728
*/
2829
public function __construct(array $parameters = []);
2930

3031
/**
31-
* @return array
32+
* @return array<string, mixed>
3233
*/
3334
public function toArray(): array;
3435

lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ public function increment(int $step = 1): ExtendedCacheItemInterface;
166166
public function decrement(int $step = 1): ExtendedCacheItemInterface;
167167

168168
/**
169-
* @param array|string $data
169+
* @param mixed[]|string $data
170170
*
171171
* @return ExtendedCacheItemInterface
172172
* @throws PhpfastcacheInvalidTypeException
173173
*/
174174
public function append(array|string $data): ExtendedCacheItemInterface;
175175

176176
/**
177-
* @param array|string $data
177+
* @param mixed[]|string $data
178178
*
179179
* @return ExtendedCacheItemInterface
180180
* @throws PhpfastcacheInvalidTypeException

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use RuntimeException;
3434

3535
/**
36-
* @method array driverUnwrapTags(array $wrapper)
36+
* @method string[] driverUnwrapTags(array $wrapper)
3737
* @method void cleanItemTags(ExtendedCacheItemInterface $item)
3838
*/
3939
trait CacheItemPoolTrait
@@ -92,8 +92,7 @@ public function setItem(CacheItemInterface $item): static
9292
}
9393

9494
/**
95-
* @param array $keys
96-
* @return array
95+
* @inheritDoc
9796
* @throws PhpfastcacheCoreException
9897
* @throws PhpfastcacheDriverException
9998
* @throws PhpfastcacheInvalidArgumentException
@@ -278,8 +277,7 @@ public function clear(): bool
278277
}
279278

280279
/**
281-
* @param array $keys
282-
* @return bool
280+
* @inheritDoc
283281
* @throws PhpfastcacheCoreException
284282
* @throws PhpfastcacheDriverException
285283
* @throws PhpfastcacheInvalidArgumentException

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ trait DriverBaseTrait
4040
use ClassNamespaceResolverTrait;
4141
use EventManagerDispatcherTrait;
4242

43+
/**
44+
* @var string[]
45+
*/
4346
protected static array $cacheItemClasses = [];
4447

4548
protected ConfigurationOptionInterface $config;
4649

50+
/**
51+
* @var object|array<mixed>|null
52+
*/
4753
protected object|array|null $instance;
4854

4955
protected string $driverName;
@@ -136,7 +142,7 @@ public static function getItemClass(): string
136142
/**
137143
* @param ExtendedCacheItemInterface $item
138144
* @param bool $stringifyDate
139-
* @return array
145+
* @return array<string, mixed>
140146
* @throws PhpfastcacheLogicException
141147
*/
142148
public function driverPreWrap(ExtendedCacheItemInterface $item, bool $stringifyDate = false): array
@@ -191,7 +197,7 @@ public function setConfig(ConfigurationOptionInterface $config): static
191197
}
192198

193199
/**
194-
* @param array $wrapper
200+
* @param array<string, mixed> $wrapper
195201
* @return mixed
196202
* @throws \Exception
197203
*/
@@ -201,7 +207,7 @@ public function driverUnwrapData(array $wrapper): mixed
201207
}
202208

203209
/**
204-
* @param array $wrapper
210+
* @param array<string, mixed> $wrapper
205211
* @return DateTimeInterface
206212
*/
207213
public function driverUnwrapEdate(array $wrapper): \DateTimeInterface
@@ -214,7 +220,7 @@ public function driverUnwrapEdate(array $wrapper): \DateTimeInterface
214220
}
215221

216222
/**
217-
* @param array $wrapper
223+
* @param array<string, mixed> $wrapper
218224
* @return DateTimeInterface|null
219225
*/
220226
public function driverUnwrapCdate(array $wrapper): ?\DateTimeInterface
@@ -227,7 +233,7 @@ public function driverUnwrapCdate(array $wrapper): ?\DateTimeInterface
227233
}
228234

229235
/**
230-
* @param array $wrapper
236+
* @param array<string, mixed> $wrapper
231237
* @return DateTimeInterface|null
232238
*/
233239
public function driverUnwrapMdate(array $wrapper): ?\DateTimeInterface
@@ -251,10 +257,10 @@ public function getInstanceId(): string
251257
* Encode data types such as object/array
252258
* for driver that does not support
253259
* non-scalar value
254-
* @param $data
260+
* @param mixed $data
255261
* @return string
256262
*/
257-
protected function encode($data): string
263+
protected function encode(mixed $data): string
258264
{
259265
return \serialize($data);
260266
}

lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract protected function driverConnect(): bool;
3333

3434
/**
3535
* @param ExtendedCacheItemInterface $item
36-
* @return ?array
36+
* @return ?array<string, mixed>
3737
*/
3838
abstract protected function driverRead(ExtendedCacheItemInterface $item): ?array;
3939

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getItem(string $key): ExtendedCacheItemInterface;
122122
* @param string[] $keys
123123
* An indexed array of keys of items to retrieve.
124124
*
125-
* @return ExtendedCacheItemInterface[]
125+
* @return iterable<ExtendedCacheItemInterface>
126126
* A traversable collection of Cache Items keyed by the cache keys of
127127
* each item. A Cache item will be returned for each key, even if that
128128
* key is not found. However, if no keys are specified then an empty
@@ -137,8 +137,7 @@ public function getItems(array $keys = []): iterable;
137137
/**
138138
* Returns A json string that represents an array of items.
139139
*
140-
* @param array $keys
141-
* An indexed array of keys of items to retrieve.
140+
* @param array<string> $keys An indexed array of keys of items to retrieve.
142141
* @param int $options \json_encode() options
143142
* @param int $depth \json_encode() depth
144143
*

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ trait ExtendedCacheItemPoolTrait
3030
use CacheItemPoolTrait;
3131

3232
/**
33-
* @param array $keys
34-
* @param int $options
35-
* @param int $depth
36-
* @return string
33+
* @inheritDoc
3734
* @throws PhpfastcacheCoreException
3835
* @throws PhpfastcacheDriverException
3936
* @throws PhpfastcacheInvalidArgumentException

lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait IOHelperTrait
3333
use TaggableCacheItemPoolTrait;
3434

3535
/**
36-
* @var array
36+
* @var array<string, string>
3737
*/
3838
public array $tmp = [];
3939

@@ -51,13 +51,13 @@ public function getStats(): DriverStatistic
5151
if (!is_dir($path)) {
5252
throw new PhpfastcacheIOException("Can't read PATH:" . $path);
5353
}
54-
$stat->setRawData(
55-
[
54+
$stat->setSize(Directory::dirSize($path))
55+
->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path))
56+
->setRawData(
57+
[
5658
'tmp' => $this->tmp,
5759
]
58-
)
59-
->setSize(Directory::dirSize($path))
60-
->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path));
60+
);
6161

6262
if ($this->getConfig()->isUseStaticItemCaching()) {
6363
$stat->setData(implode(', ', \array_keys($this->itemInstances)));
@@ -283,7 +283,7 @@ protected function writeFile(string $file, string $data, bool $secureFileManipul
283283
dirname($file) . \DIRECTORY_SEPARATOR . 'tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()(
284284
\bin2hex(\random_bytes(16))
285285
)
286-
) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999);
286+
) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999);
287287

288288
$handle = \fopen($tmpFilename, 'w+b');
289289
if (\is_resource($handle)) {
@@ -304,6 +304,6 @@ protected function writeFile(string $file, string $data, bool $secureFileManipul
304304
}
305305
}
306306

307-
return (bool) ($octetWritten ?? false);
307+
return (bool)($octetWritten ?? false);
308308
}
309309
}

lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function decrementItemsByTags(array $tagNames, int $step = 1, int $strate
216216
* @param string $tagName
217217
* The tag for which to append
218218
*
219-
* @param array|string $data
219+
* @param array<mixed>|string $data
220220
*
221221
* @param int $strategy
222222
*
@@ -235,7 +235,7 @@ public function appendItemsByTag(string $tagName, array|string $data, int $strat
235235
* @param string[] $tagNames
236236
* The tag for which to append
237237
*
238-
* @param array|string $data
238+
* @param array<mixed>|string $data
239239
*
240240
* @param int $strategy
241241
*
@@ -254,7 +254,7 @@ public function appendItemsByTags(array $tagNames, array|string $data, int $stra
254254
* @param string $tagName
255255
* The tag for which to prepend
256256
*
257-
* @param array|string $data
257+
* @param array<mixed>|string $data
258258
*
259259
* @param int $strategy
260260
*
@@ -273,7 +273,7 @@ public function prependItemsByTag(string $tagName, array|string $data, int $stra
273273
* @param string[] $tagNames
274274
* The tag for which to prepend
275275
*
276-
* @param array|string $data
276+
* @param array<mixed>|string $data
277277
*
278278
* @param int $strategy
279279
*

0 commit comments

Comments
 (0)