Skip to content

Commit af1c6aa

Browse files
authored
Merge pull request #10 from byjg/5.0
New version 5.0 - Php 8.3
2 parents 606c28d + 36544b8 commit af1c6aa

24 files changed

+421
-218
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: byjg

.github/workflows/phpunit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19+
- "8.3"
1920
- "8.2"
2021
- "8.1"
21-
- "8.0"
22-
- "7.4"
2322

2423
# Service containers to run
2524
services:
@@ -37,6 +36,7 @@ jobs:
3736
- uses: actions/checkout@v4
3837
- run: composer install
3938
- run: ./vendor/bin/phpunit --stderr
39+
- run: ./vendor/bin/psalm
4040

4141
Documentation:
4242
if: github.ref == 'refs/heads/master'

.run/PHPUnit.run.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="PHPUnit" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
3+
<TestRunner bootstrap_file="$PROJECT_DIR$/phpunit.xml.dist" configuration_file="$PROJECT_DIR$/phpunit.xml.dist" directory="$PROJECT_DIR$" scope="XML" options="--stderr" use_alternative_configuration_file="true" />
4+
<method v="2" />
5+
</configuration>
6+
</component>

.run/PSalm.run.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="PSalm" type="PhpLocalRunConfigurationType" factoryName="PHP Console" path="$PROJECT_DIR$/vendor/bin/psalm">
3+
<method v="2" />
4+
</configuration>
5+
</component>

composer.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@
66
"ByJG\\Cache\\": "src/"
77
}
88
},
9+
"autoload-dev": {
10+
"psr-4": {
11+
"Tests\\": "tests/"
12+
}
13+
},
914
"require": {
10-
"php": ">=7.4",
11-
"psr/cache": "^1.0|^2.0",
15+
"php": ">=8.1 <8.4",
16+
"psr/cache": "^1.0|^2.0|^3.0",
1217
"psr/log": "^1.0|^1.1|^2.0",
1318
"psr/simple-cache": "^1.0|^2.0",
1419
"psr/container": "^1.0|^1.1|^2.0"
1520
},
1621
"require-dev": {
17-
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
22+
"phpunit/phpunit": "^9.6",
23+
"vimeo/psalm": "^5.9"
1824
},
1925
"suggest": {
2026
"ext-memcached": "*",
21-
"ext-redis": "*"
27+
"ext-redis": "*",
28+
"ext-shmop": "*"
2229
},
2330
"provide": {
2431
"psr/cache-implementation": "1.0",

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<directory name="tests" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
</psalm>

src/CacheAvailabilityInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ interface CacheAvailabilityInterface
99
* Return if this CacheEngine is available for use
1010
* @return bool
1111
*/
12-
public function isAvailable();
12+
public function isAvailable(): bool;
1313
}

src/CacheLockInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ interface CacheLockInterface
1414
* Lock resource before set it.
1515
* @param string $key
1616
*/
17-
public function lock($key);
17+
public function lock(string $key): void;
1818

1919
/**
2020
* Unlock resource
2121
* @param string $key
2222
*/
23-
public function unlock($key);
23+
public function unlock(string $key): void;
2424
}

src/Factory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,58 @@
1010
use ByJG\Cache\Psr16\SessionCacheEngine;
1111
use ByJG\Cache\Psr16\ShmopCacheEngine;
1212
use ByJG\Cache\Psr6\CachePool;
13+
use Psr\Log\LoggerInterface;
1314

1415
class Factory
1516
{
16-
public static function createNullPool()
17+
public static function createNullPool(): CachePool
1718
{
1819
return new CachePool(
1920
new NoCacheEngine()
2021
);
2122
}
2223

23-
public static function createSessionPool($prefix = null, $bufferSize = null)
24+
public static function createSessionPool(string $prefix = 'cache', int $bufferSize = 10): CachePool
2425
{
2526
return new CachePool(
2627
new SessionCacheEngine($prefix),
2728
$bufferSize
2829
);
2930
}
3031

31-
public static function createFilePool($prefix = null, $path = null, $bufferSize = null, $logger = null)
32+
public static function createFilePool(string $prefix = 'cache', ?string $path = null, int $bufferSize = 10, ?LoggerInterface $logger = null, bool $createPath = false): CachePool
3233
{
3334
return new CachePool(
34-
new FileSystemCacheEngine($prefix, $path, $logger),
35+
new FileSystemCacheEngine($prefix, $path, $logger, $createPath),
3536
$bufferSize
3637
);
3738
}
3839

39-
public static function createShmopPool($config = [], $bufferSize = null, $logger = null)
40+
public static function createShmopPool(array $config = [], int $bufferSize = 10, ?LoggerInterface $logger = null): CachePool
4041
{
4142
return new CachePool(
4243
new ShmopCacheEngine($config, $logger),
4344
$bufferSize
4445
);
4546
}
4647

47-
public static function createArrayPool($bufferSize = null, $logger = null)
48+
public static function createArrayPool(int $bufferSize = 10, ?LoggerInterface $logger = null): CachePool
4849
{
4950
return new CachePool(
5051
new ArrayCacheEngine($logger),
5152
$bufferSize
5253
);
5354
}
5455

55-
public static function createMemcachedPool($servers = null, $bufferSize = null, $logger = null)
56+
public static function createMemcachedPool(?array $servers = null, int $bufferSize = 10, ?LoggerInterface $logger = null): CachePool
5657
{
5758
return new CachePool(
5859
new MemcachedEngine($servers, $logger),
5960
$bufferSize
6061
);
6162
}
6263

63-
public static function createRedisCacheEngine($servers = null, $password = null, $bufferSize = null, $logger = null)
64+
public static function createRedisCacheEngine(?string $servers = null, ?string $password = null, int $bufferSize = 10, ?LoggerInterface $logger = null): CachePool
6465
{
6566
return new CachePool(
6667
new RedisCacheEngine($servers, $password, $logger),

src/Psr16/ArrayCacheEngine.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
namespace ByJG\Cache\Psr16;
44

5+
use ByJG\Cache\Exception\InvalidArgumentException;
56
use DateInterval;
7+
use Psr\Container\ContainerExceptionInterface;
8+
use Psr\Container\NotFoundExceptionInterface;
9+
use Psr\Log\LoggerInterface;
610
use Psr\Log\NullLogger;
711

812
class ArrayCacheEngine extends BaseCacheEngine
913
{
1014

11-
protected $cache = array();
15+
protected array $cache = [];
1216

13-
protected $logger = null;
17+
protected LoggerInterface|null $logger = null;
1418

15-
public function __construct($logger = null)
19+
public function __construct(LoggerInterface|null $logger = null)
1620
{
1721
$this->logger = $logger;
1822
if (is_null($logger)) {
@@ -29,10 +33,11 @@ public function __construct($logger = null)
2933
*
3034
* @param string $key The cache item key.
3135
* @return bool
32-
* @throws \Psr\SimpleCache\InvalidArgumentException
33-
* MUST be thrown if the $key string is not a legal value.
36+
* @throws InvalidArgumentException
37+
* @throws ContainerExceptionInterface
38+
* @throws NotFoundExceptionInterface
3439
*/
35-
public function has($key)
40+
public function has(string $key): bool
3641
{
3742
$key = $this->getKeyFromContainer($key);
3843
if (isset($this->cache[$key])) {
@@ -51,9 +56,11 @@ public function has($key)
5156
* @param string $key The object KEY
5257
* @param mixed $default IGNORED IN MEMCACHED.
5358
* @return mixed Description
54-
* @throws \Psr\SimpleCache\InvalidArgumentException
59+
* @throws ContainerExceptionInterface
60+
* @throws InvalidArgumentException
61+
* @throws NotFoundExceptionInterface
5562
*/
56-
public function get($key, $default = null)
63+
public function get(string $key, mixed $default = null): mixed
5764
{
5865
if ($this->has($key)) {
5966
$key = $this->getKeyFromContainer($key);
@@ -78,7 +85,7 @@ public function get($key, $default = null)
7885
*
7986
* MUST be thrown if the $key string is not a legal value.
8087
*/
81-
public function set($key, $value, $ttl = null)
88+
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
8289
{
8390
$key = $this->getKeyFromContainer($key);
8491

@@ -92,9 +99,10 @@ public function set($key, $value, $ttl = null)
9299
return true;
93100
}
94101

95-
public function clear()
102+
public function clear(): bool
96103
{
97104
$this->cache = [];
105+
return true;
98106
}
99107

100108
/**
@@ -103,7 +111,7 @@ public function clear()
103111
* @param string $key
104112
* @return bool
105113
*/
106-
public function delete($key)
114+
public function delete(string $key): bool
107115
{
108116
$key = $this->getKeyFromContainer($key);
109117

@@ -112,7 +120,7 @@ public function delete($key)
112120
return true;
113121
}
114122

115-
public function isAvailable()
123+
public function isAvailable(): bool
116124
{
117125
return true;
118126
}

0 commit comments

Comments
 (0)