Skip to content

Commit 54ce900

Browse files
committed
Increased Phpstan level to 4 for even more strict validation
1 parent 6094d0b commit 54ce900

File tree

10 files changed

+27
-33
lines changed

10 files changed

+27
-33
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
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 3 -c phpstan_lite.neon 2>&1
44+
run: ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1
4545

4646
- name: Run TESTS
4747
env:

.travis.yml

Lines changed: 1 addition & 1 deletion
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 3 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 3 -c phpstan_lite.neon 2>&1"
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"
6363
- php -f ./bin/ci/run_tests.php

lib/Phpfastcache/Config/ConfigurationOption.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ protected function getDefaultSuperGlobalAccessor(): \Closure
346346
'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER,
347347
'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST,
348348
'COOKIE' => $keyName !== null ? $_COOKIE[$keyName] ?? null : $_COOKIE,
349+
default => null,
349350
};
350351
});
351352
}

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,9 @@ public function getItem(string $key): ExtendedCacheItemInterface
227227
$this->eventManager->dispatch(Event::CACHE_GET_ITEM, $this, $item);
228228

229229
$item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
230-
231-
return $item;
232230
}
233-
throw new PhpfastcacheInvalidArgumentException(\sprintf('Item %s was not built due to an unknown error', \gettype($key)));
231+
232+
return $item;
234233
}
235234

236235
/**
@@ -354,7 +353,7 @@ public function commit(): bool
354353
$return = true;
355354
foreach ($this->deferredList as $key => $item) {
356355
$result = $this->save($item);
357-
if ($return !== true) {
356+
if ($result !== true) {
358357
unset($this->deferredList[$key]);
359358
$return = $result;
360359
}

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ public function driverPreWrap(ExtendedCacheItemInterface $item, bool $stringifyD
150150
];
151151

152152
if ($this->getConfig()->isItemDetailedDate()) {
153-
$wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = new DateTime();
153+
$wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = $item->getModificationDate();
154154
/**
155155
* If the creation date exists
156156
* reuse it else set a new Date
157157
*/
158-
$wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate() ?: new DateTime();
158+
$wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate();
159159
} else {
160160
$wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = null;
161161
$wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = null;

lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function deleteItemsByTags(array $tagNames, int $strategy = TaggableCache
157157

158158
foreach ($this->getItemsByTags($tagNames, $strategy) as $item) {
159159
$result = $this->deleteItem($item->getKey());
160-
if ($return !== true) {
160+
if ($result !== true) {
161161
$return = $result;
162162
}
163163
}
@@ -179,7 +179,7 @@ public function deleteItemsByTag(string $tagName, int $strategy = TaggableCacheI
179179
$return = true;
180180
foreach ($this->getItemsByTag($tagName, $strategy) as $item) {
181181
$result = $this->deleteItem($item->getKey());
182-
if ($return !== true) {
182+
if ($result !== true) {
183183
$return = $result;
184184
}
185185
}
@@ -225,7 +225,7 @@ public function incrementItemsByTags(array $tagNames, int $step = 1, int $strate
225225
$return = true;
226226
foreach ($tagNames as $tagName) {
227227
$result = $this->incrementItemsByTag($tagName, $step, $strategy);
228-
if ($return !== true) {
228+
if ($result !== true) {
229229
$return = $result;
230230
}
231231
}
@@ -270,7 +270,7 @@ public function decrementItemsByTags(array $tagNames, int $step = 1, int $strate
270270
$return = true;
271271
foreach ($tagNames as $tagName) {
272272
$result = $this->decrementItemsByTag($tagName, $step, $strategy);
273-
if ($return !== true) {
273+
if ($result !== true) {
274274
$return = $result;
275275
}
276276
}
@@ -315,7 +315,7 @@ public function appendItemsByTags(array $tagNames, array|string $data, int $stra
315315
$return = true;
316316
foreach ($tagNames as $tagName) {
317317
$result = $this->appendItemsByTag($tagName, $data, $strategy);
318-
if ($return !== true) {
318+
if ($result !== true) {
319319
$return = $result;
320320
}
321321
}
@@ -360,7 +360,7 @@ public function prependItemsByTags(array $tagNames, array|string $data, int $str
360360
$return = true;
361361
foreach ($tagNames as $tagName) {
362362
$result = $this->prependItemsByTag($tagName, $data, $strategy);
363-
if ($return !== true) {
363+
if ($result !== true) {
364364
$return = $result;
365365
}
366366
}

lib/Phpfastcache/Drivers/Cassandra/Driver.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Class Driver
34-
* @property CassandraSession $instance Instance of driver service
34+
* @property CassandraSession|null $instance Instance of driver service
3535
* @method Config getConfig()
3636
*/
3737
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
@@ -56,10 +56,6 @@ public function driverCheck(): bool
5656
*/
5757
protected function driverConnect(): bool
5858
{
59-
if ($this->instance instanceof CassandraSession) {
60-
throw new PhpfastcacheLogicException('Already connected to Couchbase server');
61-
}
62-
6359
$clientConfig = $this->getConfig();
6460

6561
$clusterBuilder = Cassandra::cluster()
@@ -82,7 +78,7 @@ protected function driverConnect(): bool
8278
$clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword());
8379
}
8480

85-
$this->instance = $clusterBuilder->build()->connect();
81+
$this->instance = $clusterBuilder->build()->connect('');
8682

8783
/**
8884
* In case of emergency:
@@ -97,9 +93,10 @@ protected function driverConnect(): bool
9793
"CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };",
9894
self::CASSANDRA_KEY_SPACE
9995
)
100-
)
96+
),
97+
[]
10198
);
102-
$this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)));
99+
$this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)), []);
103100
$this->instance->execute(
104101
new Cassandra\SimpleStatement(
105102
sprintf(
@@ -115,7 +112,8 @@ protected function driverConnect(): bool
115112
);',
116113
self::CASSANDRA_TABLE
117114
)
118-
)
115+
),
116+
[]
119117
);
120118

121119
return true;

lib/Phpfastcache/Drivers/Leveldb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function driverConnect(): bool
131131
throw new PhpfastcacheLogicException('Already connected to Leveldb database');
132132
}
133133

134-
$this->instance = $this->instance ?: new LeveldbClient($this->getLeveldbFile());
134+
$this->instance = new LeveldbClient($this->getLeveldbFile());
135135

136136
return true;
137137
}

lib/Phpfastcache/Drivers/Mongodb/Driver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ protected function driverConnect(): bool
8787
$databaseName = $this->getConfig()->getDatabaseName();
8888
$driverOptions = $this->getConfig()->getDriverOptions();
8989

90-
$this->instance = $this->instance ?? new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout], $driverOptions);
91-
$this->database = $this->database ?? $this->instance->selectDatabase($databaseName);
90+
$this->instance = new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout], $driverOptions);
91+
$this->database = $this->instance->selectDatabase($databaseName);
9292

9393
if (!$this->collectionExists($collectionName)) {
9494
$this->database->createCollection($collectionName);
@@ -162,7 +162,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
162162
self::DRIVER_CDATE_WRAPPER_INDEX => new UTCDateTime($item->getCreationDate()),
163163
];
164164
}
165-
$result = (array)$this->getCollection()->updateOne(
165+
$result = $this->getCollection()->updateOne(
166166
['_id' => $this->getMongoDbItemKey($item)],
167167
[
168168
'$set' => $set,
@@ -173,7 +173,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
173173
throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server: ' . $e->getMessage(), 0, $e);
174174
}
175175

176-
return !isset($result['ok']) || (int) $result['ok'] === 1;
176+
return $result->isAcknowledged();
177177
}
178178

179179
/**

lib/Phpfastcache/Helper/Psr16Adapter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,11 @@ public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null
189189
public function deleteMultiple(iterable $keys): bool
190190
{
191191
try {
192-
if ($keys instanceof Traversable) {
193-
return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
194-
}
195-
196192
if (\is_array($keys)) {
197193
return $this->internalCacheInstance->deleteItems($keys);
198194
}
199195

200-
throw new PhpfastcacheInvalidArgumentException('$keys must be an array/Traversable instance.');
196+
return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
201197
} catch (PhpfastcacheInvalidArgumentException $e) {
202198
throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e);
203199
}

0 commit comments

Comments
 (0)