Skip to content

Commit 6094d0b

Browse files
committed
Increased Phpstan level to 3 for more strict validation
1 parent d63bb12 commit 6094d0b

File tree

35 files changed

+61
-176
lines changed

35 files changed

+61
-176
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 2 -c phpstan_lite.neon 2>&1
44+
run: ./vendor/bin/phpstan analyse lib/ -l 3 -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 2 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 2 -c phpstan_lite.neon 2>&1"
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"
6363
- php -f ./bin/ci/run_tests.php

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"ext-apcu": "*",
3838
"ext-intl": "*",
3939
"ext-memcached": "*",
40+
"ext-cassandra": "*",
4041
"ext-memcache": "*",
4142
"ext-mongodb": "*",
4243
"ext-redis": "*",

lib/Phpfastcache/Cluster/ClusterPoolAbstract.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
use Psr\Cache\CacheItemInterface;
3939
use Psr\Cache\InvalidArgumentException;
4040

41-
/**
42-
* @property ConfigurationOption $config
43-
*/
4441
abstract class ClusterPoolAbstract implements ClusterPoolInterface
4542
{
4643
use TaggableCacheItemPoolTrait;
@@ -242,9 +239,4 @@ public function getStats(): DriverStatistic
242239

243240
return $stats;
244241
}
245-
246-
public function getConfig(): ConfigurationOption
247-
{
248-
return $this->config;
249-
}
250242
}

lib/Phpfastcache/Config/ConfigurationOptionInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function isValueSerializable(mixed $val): bool;
4242
*/
4343
public function isValidOption(string $optionName): bool;
4444

45+
/**
46+
* @return bool
47+
*/
48+
public function isItemDetailedDate(): bool;
49+
4550
/**
4651
* @param bool $itemDetailedDate
4752
* @return ConfigurationOption

lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getTtl(): int
177177

178178
public function isExpired(): bool
179179
{
180-
return $this->expirationDate->getTimestamp() < (new DateTime())->getTimestamp();
180+
return $this->getTtl() <= 0;
181181
}
182182

183183
public function isNull(): bool
@@ -319,12 +319,12 @@ public function cloneInto(ExtendedCacheItemInterface $itemTarget, ?ExtendedCache
319319
->set($this->getRawValue())
320320
->setHit($this->isHit())
321321
->setTags($this->getTags())
322-
->expiresAt($this->getExpirationDate())
322+
->expiresAt(clone $this->getExpirationDate())
323323
->setDriver($itemPoolTarget ?? $this->driver);
324324

325325
if ($this->driver->getConfig()->isItemDetailedDate()) {
326-
$itemTarget->setCreationDate($this->getCreationDate())
327-
->setModificationDate($this->getModificationDate());
326+
$itemTarget->setCreationDate(clone $this->getCreationDate())
327+
->setModificationDate(clone $this->getModificationDate());
328328
}
329329
}
330330

lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ trait CacheItemPoolTrait
4040
protected static string $unsupportedKeyChars = '{}()/\@:';
4141

4242
/**
43-
* @var ExtendedCacheItemInterface[]
43+
* @var ExtendedCacheItemInterface[]|CacheItemInterface[]
4444
*/
4545
protected array $deferredList = [];
4646

4747
/**
48-
* @var ExtendedCacheItemInterface[]
48+
* @var ExtendedCacheItemInterface[]|CacheItemInterface[]
4949
*/
5050
protected array $itemInstances = [];
5151

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ public function getDriverName(): string
103103
}
104104

105105
/**
106-
* @return ConfigurationOption
106+
* @return ConfigurationOptionInterface
107107
*/
108-
public function getDefaultConfig(): ConfigurationOption
108+
public function getDefaultConfig(): ConfigurationOptionInterface
109109
{
110110
$className = $this::getConfigClass();
111111

@@ -174,9 +174,12 @@ public function driverPreWrap(ExtendedCacheItemInterface $item, bool $stringifyD
174174
}
175175

176176
/**
177-
* @return ConfigurationOption
177+
* @return ConfigurationOptionInterface
178178
*/
179-
abstract public function getConfig(): ConfigurationOption;
179+
public function getConfig(): ConfigurationOptionInterface
180+
{
181+
return $this->config;
182+
}
180183

181184
/**
182185
* @param ConfigurationOptionInterface $config

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use InvalidArgumentException;
2020
use Phpfastcache\Config\ConfigurationOption;
21+
use Phpfastcache\Config\ConfigurationOptionInterface;
2122
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2223
use Phpfastcache\Entities\DriverIO;
2324
use Phpfastcache\Entities\DriverStatistic;
@@ -76,14 +77,14 @@ public static function getConfigClass(): string;
7677
public static function getItemClass(): string;
7778

7879
/**
79-
* @return ConfigurationOption
80+
* @return ConfigurationOptionInterface
8081
*/
81-
public function getConfig(): ConfigurationOption;
82+
public function getConfig(): ConfigurationOptionInterface;
8283

8384
/**
84-
* @return ConfigurationOption
85+
* @return ConfigurationOptionInterface
8586
*/
86-
public function getDefaultConfig(): ConfigurationOption;
87+
public function getDefaultConfig(): ConfigurationOptionInterface;
8788

8889
/**
8990
* @return string

lib/Phpfastcache/Drivers/Apcu/Driver.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* Class Driver
32-
* @property Config $config
32+
* @method Config getConfig()
3333
*/
3434
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
3535
{
@@ -118,9 +118,4 @@ protected function driverClear(): bool
118118
{
119119
return @apcu_clear_cache();
120120
}
121-
122-
public function getConfig(): Config
123-
{
124-
return $this->config;
125-
}
126121
}

0 commit comments

Comments
 (0)