Skip to content

Commit 9d86030

Browse files
committed
Ps2 compliance + added php ext-intl suggestion
1 parent d38fea3 commit 9d86030

24 files changed

+95
-106
lines changed

V5-ROADMAP.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
- [x] Implement CouchBase Driver
1818
- [x] Implement Dev Driver (return null/bool everywhere for development purpose)
1919
- [x] Implement advanced tags features: incrementByTag(s), decrementByTag(s), appendByTag(s), prependByTag(s), expiresAfterByTag(s)
20+
- [x] Final code review + psr2 checks + psr-6 null value as legitimates value.
2021
- [ ] Check Wincache driver in real Windows env (and not in VM)
21-
- [ ] Final code review + psr2 checks + psr-6 null value as legitimates value.
2222
- [ ] Rewrite Wiki

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"suggest": {
2929
"ext-apc": "*",
30+
"ext-intl": "*",
3031
"ext-mbstring": "*",
3132
"ext-memcached": "*",
3233
"ext-memcache": "*",

src/phpFastCache/Cache/DriverBaseTrait.php

+2-25
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,10 @@ public function getTagKeys(array $keys)
303303
*/
304304
public static function isValidOption($optionName, $optionValue)
305305
{
306-
if(!is_string($optionName))
307-
{
306+
if (!is_string($optionName)) {
308307
throw new \InvalidArgumentException('$optionName must be a string');
309308
}
309+
310310
return true;
311311
}
312312

@@ -325,27 +325,4 @@ public static function getValidOptions()
325325
{
326326
return [];
327327
}
328-
329-
/**
330-
* Serialization protection for frameworks
331-
* with profiler such as Symfony, etc.
332-
*/
333-
/* public function __sleep()
334-
{
335-
$this->itemInstances = array_keys($this->itemInstances);
336-
return (array) array_keys(get_object_vars($this));
337-
}*/
338-
339-
/**
340-
* Serialization protection for frameworks
341-
* with profiler such as Symfony, etc.
342-
*/
343-
/* public function __wakeup()
344-
{
345-
$itemInstances = $this->itemInstances;
346-
$this->itemInstances = [];
347-
foreach ($itemInstances as $itemInstance) {
348-
$this->itemInstances[$itemInstance] = $this->getItem($itemInstance);
349-
}
350-
}*/
351328
}

src/phpFastCache/Cache/ExtendedCacheItemInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function isExpired();
4747
* @return mixed
4848
*/
4949
public function setDriver(ExtendedCacheItemPoolInterface $driver);
50-
50+
5151
/**
5252
* @param bool $isHit
5353
* @return $this

src/phpFastCache/Cache/ExtendedCacheItemPoolInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
namespace phpFastCache\Cache;
1616

17+
use InvalidArgumentException;
1718
use phpFastCache\Entities\driverStatistic;
1819
use Psr\Cache\CacheItemInterface;
1920
use Psr\Cache\CacheItemPoolInterface;
20-
use \InvalidArgumentException;
2121

2222
/**
2323
* Interface ExtendedCacheItemPoolInterface
@@ -72,7 +72,7 @@ public function getItem($key);
7272
* key is not found. However, if no keys are specified then an empty
7373
* traversable MUST be returned instead.
7474
*/
75-
public function getItems(array $keys = array());
75+
public function getItems(array $keys = []);
7676

7777
/**
7878
* @param \Psr\Cache\CacheItemInterface $item

src/phpFastCache/Cache/ItemBaseTrait.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ public function isHit()
114114
*/
115115
public function setHit($isHit)
116116
{
117-
if(is_bool($isHit)){
117+
if (is_bool($isHit)) {
118118
$this->isHit = $isHit;
119+
119120
return $this;
120-
}else{
121+
} else {
121122
throw new \InvalidArgumentException('$isHit must be a boolean');
122123
}
123124
}
@@ -400,13 +401,13 @@ public function getRemovedTags()
400401
/**
401402
* @throws \RuntimeException
402403
*/
403-
/* final public function __sleep()
404-
{
405-
$info = get_object_vars($this);
406-
$info[ 'driver' ] = 'object(' . get_class($info[ 'driver' ]) . ')';
407-
408-
return (array) $info;
409-
}*/
404+
/* final public function __sleep()
405+
{
406+
$info = get_object_vars($this);
407+
$info[ 'driver' ] = 'object(' . get_class($info[ 'driver' ]) . ')';
408+
409+
return (array) $info;
410+
}*/
410411

411412
/**
412413
* Prevent recursions for Debug (php 5.6+)

src/phpFastCache/Core/ExtendedCacheItemPoolTrait.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function incrementItemsByTag($tagName, $step = 1)
104104
$item->increment($step);
105105
$this->saveDeferred($item);
106106
}
107+
107108
return $this->commit();
108109
} else {
109110
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
@@ -116,8 +117,7 @@ public function incrementItemsByTag($tagName, $step = 1)
116117
public function incrementItemsByTags(array $tagNames, $step = 1)
117118
{
118119
$return = null;
119-
foreach ($tagNames as $tagName)
120-
{
120+
foreach ($tagNames as $tagName) {
121121
$result = $this->incrementItemsByTag($tagName, $step);
122122
if ($return !== false) {
123123
$return = $result;
@@ -137,6 +137,7 @@ public function decrementItemsByTag($tagName, $step = 1)
137137
$item->decrement($step);
138138
$this->saveDeferred($item);
139139
}
140+
140141
return $this->commit();
141142
} else {
142143
throw new InvalidArgumentException('$tagName must be a string and $step an integer');
@@ -149,8 +150,7 @@ public function decrementItemsByTag($tagName, $step = 1)
149150
public function decrementItemsByTags(array $tagNames, $step = 1)
150151
{
151152
$return = null;
152-
foreach ($tagNames as $tagName)
153-
{
153+
foreach ($tagNames as $tagName) {
154154
$result = $this->decrementItemsByTag($tagName, $step);
155155
if ($return !== false) {
156156
$return = $result;
@@ -170,6 +170,7 @@ public function appendItemsByTag($tagName, $data)
170170
$item->append($data);
171171
$this->saveDeferred($item);
172172
}
173+
173174
return $this->commit();
174175
} else {
175176
throw new InvalidArgumentException('$tagName must be a string');
@@ -182,8 +183,7 @@ public function appendItemsByTag($tagName, $data)
182183
public function appendItemsByTags(array $tagNames, $data)
183184
{
184185
$return = null;
185-
foreach ($tagNames as $tagName)
186-
{
186+
foreach ($tagNames as $tagName) {
187187
$result = $this->decrementItemsByTag($tagName, $data);
188188
if ($return !== false) {
189189
$return = $result;
@@ -203,6 +203,7 @@ public function prependItemsByTag($tagName, $data)
203203
$item->prepend($data);
204204
$this->saveDeferred($item);
205205
}
206+
206207
return $this->commit();
207208
} else {
208209
throw new InvalidArgumentException('$tagName must be a string');
@@ -215,8 +216,7 @@ public function prependItemsByTag($tagName, $data)
215216
public function prependItemsByTags(array $tagNames, $data)
216217
{
217218
$return = null;
218-
foreach ($tagNames as $tagName)
219-
{
219+
foreach ($tagNames as $tagName) {
220220
$result = $this->decrementItemsByTag($tagName, $data);
221221
if ($return !== false) {
222222
$return = $result;

src/phpFastCache/Core/StandardPsr6StructureTrait.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getItem($key)
4545
{
4646
if (is_string($key)) {
4747
if (!array_key_exists($key, $this->itemInstances)) {
48-
48+
4949
/**
5050
* @var $item ExtendedCacheItemInterface
5151
*/
@@ -65,7 +65,7 @@ public function getItem($key)
6565
* getItem() call in delete() method
6666
*/
6767
$this->driverDelete($item);
68-
}else{
68+
} else {
6969
$item->setHit(true);
7070
}
7171
}
@@ -117,6 +117,7 @@ public function getItems(array $keys = [])
117117
public function hasItem($key)
118118
{
119119
CacheManager::$ReadHits++;
120+
120121
return $this->getItem($key)->isHit();
121122
}
122123

@@ -127,6 +128,7 @@ public function clear()
127128
{
128129
CacheManager::$WriteHits++;
129130
$this->itemInstances = [];
131+
130132
return $this->driverClear();
131133
}
132134

@@ -180,10 +182,10 @@ public function save(CacheItemInterface $item)
180182
if (!array_key_exists($item->getKey(), $this->itemInstances)) {
181183
$this->itemInstances[ $item->getKey() ] = $item;
182184
}
183-
if($this->driverWrite($item) && $this->driverWriteTags($item))
184-
{
185+
if ($this->driverWrite($item) && $this->driverWriteTags($item)) {
185186
$item->setHit(true);
186187
CacheManager::$WriteHits++;
188+
187189
return true;
188190
}
189191

src/phpFastCache/Drivers/Apc/Driver.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,13 @@ protected function driverConnect()
133133
public function getStats()
134134
{
135135
$stats = (array) apc_cache_info('user');
136-
$date = (new \DateTime())->setTimestamp($stats['start_time']);
136+
$date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]);
137+
137138
return (new driverStatistic())
138139
->setData(implode(', ', array_keys($this->itemInstances)))
139-
->setInfo(sprintf("The APC cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), $stats['num_entries']))
140+
->setInfo(sprintf("The APC cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822),
141+
$stats[ 'num_entries' ]))
140142
->setRawData($stats)
141-
->setSize($stats['mem_size']);
143+
->setSize($stats[ 'mem_size' ]);
142144
}
143145
}

src/phpFastCache/Drivers/Apcu/Driver.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function driverConnect()
120120
{
121121
return true;
122122
}
123-
123+
124124
/********************
125125
*
126126
* PSR-6 Extended Methods
@@ -133,11 +133,12 @@ protected function driverConnect()
133133
public function getStats()
134134
{
135135
$stats = (array) apc_cache_info('user');
136-
$date = (new \DateTime())->setTimestamp($stats['start_time']);
136+
$date = (new \DateTime())->setTimestamp($stats[ 'start_time' ]);
137+
137138
return (new driverStatistic())
138139
->setData(implode(', ', array_keys($this->itemInstances)))
139-
->setInfo(sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), $stats['num_entries']))
140+
->setInfo(sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(DATE_RFC2822), $stats[ 'num_entries' ]))
140141
->setRawData($stats)
141-
->setSize($stats['mem_size']);
142+
->setSize($stats[ 'mem_size' ]);
142143
}
143144
}

src/phpFastCache/Drivers/Couchbase/Driver.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
namespace phpFastCache\Drivers\Couchbase;
1616

17+
use CouchbaseCluster as CouchbaseClient;
1718
use phpFastCache\Core\DriverAbstract;
1819
use phpFastCache\Core\StandardPsr6StructureTrait;
1920
use phpFastCache\Entities\driverStatistic;
2021
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
2122
use phpFastCache\Exceptions\phpFastCacheDriverException;
2223
use Psr\Cache\CacheItemInterface;
23-
use CouchbaseCluster as CouchbaseClient;
2424

2525
/**
2626
* Class Driver
@@ -191,10 +191,11 @@ protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket)
191191
public function getStats()
192192
{
193193
$info = $this->getBucket()->manager()->info();
194+
194195
return (new driverStatistic())
195-
->setSize($info['basicStats']['diskUsed'])
196+
->setSize($info[ 'basicStats' ][ 'diskUsed' ])
196197
->setRawData($info)
197198
->setData(implode(', ', array_keys($this->itemInstances)))
198-
->setInfo('CouchBase version ' . $info[ 'nodes' ][0]['version'] . ', Uptime (in days): ' . round($info[ 'nodes' ][0][ 'uptime' ] / 86400, 1). "\n For more information see RawData.");
199+
->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData.");
199200
}
200201
}

src/phpFastCache/Drivers/Files/Driver.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
namespace phpFastCache\Drivers\Files;
1616

17-
use phpFastCache\Cache\ExtendedCacheItemInterface;
1817
use phpFastCache\Core\DriverAbstract;
1918
use phpFastCache\Core\PathSeekerTrait;
2019
use phpFastCache\Core\StandardPsr6StructureTrait;
@@ -176,8 +175,7 @@ protected function driverConnect()
176175
public static function isValidOption($optionName, $optionValue)
177176
{
178177
parent::isValidOption($optionName, $optionValue);
179-
switch($optionName)
180-
{
178+
switch ($optionName) {
181179
case 'path':
182180
return is_string($optionValue);
183181
break;
@@ -194,7 +192,7 @@ public static function isValidOption($optionName, $optionValue)
194192
break;
195193
default:
196194
return false;
197-
break;
195+
break;
198196
}
199197
}
200198

@@ -229,7 +227,7 @@ public function getStats()
229227
{
230228
$stat = new driverStatistic();
231229
$path = $this->getFilePath(false);
232-
230+
233231
if (!is_dir($path)) {
234232
throw new phpFastCacheDriverException("Can't read PATH:" . $path, 94);
235233
}

src/phpFastCache/Drivers/Files/Item.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
use phpFastCache\Cache\ExtendedCacheItemInterface;
1818
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
19-
use phpFastCache\Drivers\Files\Driver as FilesDriver;
2019
use phpFastCache\Cache\ItemBaseTrait;
20+
use phpFastCache\Drivers\Files\Driver as FilesDriver;
2121

2222
/**
2323
* Class Item

src/phpFastCache/Drivers/Leveldb/Driver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace phpFastCache\Drivers\Leveldb;
1616

17+
use LevelDB as LeveldbClient;
1718
use phpFastCache\Core\DriverAbstract;
1819
use phpFastCache\Core\PathSeekerTrait;
1920
use phpFastCache\Core\StandardPsr6StructureTrait;
@@ -22,7 +23,6 @@
2223
use phpFastCache\Exceptions\phpFastCacheDriverException;
2324
use phpFastCache\Util\Directory;
2425
use Psr\Cache\CacheItemInterface;
25-
use LevelDB as LeveldbClient;
2626

2727
/**
2828
* Class Driver

0 commit comments

Comments
 (0)