Passed
Push — master ( 2dbe85...59ef95 )
by Dan
07:33 queued 01:43
created
Src/Cache/Storage/FileStorage.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function __construct($directory, DateInterval $ttl)
47 47
     {
48
-        if (!is_string($directory)){
48
+        if (!is_string($directory)) {
49 49
             throw new InvalidArgumentException('Directory must be a valid string');
50 50
         }
51 51
 
52 52
         $this->dir = $directory;
53 53
 
54
-        if(!@mkdir($this->dir, 0755) && !is_dir($this->dir)){
54
+        if (!@mkdir($this->dir, 0755) && !is_dir($this->dir)) {
55 55
             throw new CacheException('unable to create directory');
56 56
         }
57 57
 
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         $ttl = time() + $this->getTtlTimestamp($ttl);
76 76
         $cacheItem = $this->_createCacheItem($key, $value, $ttl);
77 77
 
78
-        if (null !== $value){
79
-            \file_put_contents($cacheItem['file'],$cacheItem['data']);
80
-            if (!file_exists($cacheItem['file'])){
78
+        if (null !== $value) {
79
+            \file_put_contents($cacheItem['file'], $cacheItem['data']);
80
+            if (!file_exists($cacheItem['file'])) {
81 81
                 return false;
82 82
             }
83 83
         }
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return bool
100 100
      */
101
-    public function has($key){
102
-       if ($this->_fetchCacheFile($key)){
101
+    public function has($key) {
102
+       if ($this->_fetchCacheFile($key)) {
103 103
          return true;
104 104
        }
105 105
        return false;
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
      * @return mixed The value of the item from the cache, or $default in case of cache miss.
114 114
      *
115 115
      */
116
-    public function get($key){
117
-        if ($this->has($key)){
116
+    public function get($key) {
117
+        if ($this->has($key)) {
118 118
             return $this->previousRequest[1];
119 119
         }
120 120
         return null;
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return bool True on success and false on failure.
139 139
      */
140
-    public function clear(){
141
-        if (is_dir( $this->dir )){
140
+    public function clear() {
141
+        if (is_dir($this->dir)) {
142 142
             array_map('unlink', glob("$this->dir/*.*"));
143 143
         }
144 144
 
145 145
         $data = glob("$this->dir/*.*");
146 146
 
147
-        if (!empty($data)){
147
+        if (!empty($data)) {
148 148
             return false;
149 149
         }
150 150
 
@@ -158,20 +158,20 @@  discard block
 block discarded – undo
158 158
      * @return bool|mixed
159 159
      * @internal
160 160
      */
161
-    private function _fetchCacheFile($key){
161
+    private function _fetchCacheFile($key) {
162 162
 
163
-        $cacheFile = implode('.',[$key, FileStorage::EXTENSION]);
164
-        $cacheLocation = $this->dir . DIRECTORY_SEPARATOR . $cacheFile;
163
+        $cacheFile = implode('.', [$key, FileStorage::EXTENSION]);
164
+        $cacheLocation = $this->dir.DIRECTORY_SEPARATOR.$cacheFile;
165 165
         $this->previousRequest = false;
166 166
 
167
-        if (file_exists($cacheLocation)){
167
+        if (file_exists($cacheLocation)) {
168 168
 
169 169
             $data = \file_get_contents($cacheLocation);
170 170
             $cacheData = json_decode($data, TRUE);
171 171
             $this->previousRequest = $cacheData;
172 172
 
173 173
             //cache has expired
174
-            if ( $cacheData[0] < time() ){
174
+            if ($cacheData[0] < time()) {
175 175
                 \unlink($cacheLocation);
176 176
                 $this->previousRequest = false;
177 177
             }
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
      * @return array
189 189
      * @throws InvalidArgumentException
190 190
      */
191
-    private function _createCacheItem($key, $value, $ttl){
191
+    private function _createCacheItem($key, $value, $ttl) {
192 192
 
193
-        if (preg_match('/[\\/\\*\\\\\?.]+/i', $key)){
193
+        if (preg_match('/[\\/\\*\\\\\?.]+/i', $key)) {
194 194
             throw new InvalidArgumentException('$key must be a valid string');
195 195
         }
196 196
 
197
-        $filename = implode('.',[(string)$key, FileStorage::EXTENSION]);
197
+        $filename = implode('.', [(string)$key, FileStorage::EXTENSION]);
198 198
 
199 199
         return [
200
-            'file' => $this->dir . DIRECTORY_SEPARATOR . $filename,
200
+            'file' => $this->dir.DIRECTORY_SEPARATOR.$filename,
201 201
             'data' => json_encode([$ttl, $value])
202 202
         ];
203 203
     }
Please login to merge, or discard this patch.
Src/Cache/Cache.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     public function set($key, $value, $ttl = null)
38 38
     {
39 39
         //convert to timestamp from now.
40
-        if ($ttl instanceof \DateInterval){
40
+        if ($ttl instanceof \DateInterval) {
41 41
             $dateTime = new \DateTime();
42
-            $dateTime->add( $ttl );
42
+            $dateTime->add($ttl);
43 43
             $ttl = $dateTime->getTimestamp() - time();
44 44
         }
45 45
 
46
-        if (!is_int($ttl) ||  $ttl === null){
46
+        if (!is_int($ttl) || $ttl === null) {
47 47
             throw new InvalidArgumentException('$ttl can only be an instance of \DateInterval, int or null');
48 48
         }
49 49
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         $this->_isValidKey($key);
88 88
 
89
-        if ($this->cache->has($key)){
89
+        if ($this->cache->has($key)) {
90 90
             return $this->cache->get($key);
91 91
         }
92 92
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         $this->_isTraversable($keys);
128 128
         $result = [];
129 129
 
130
-        foreach ((array)$keys as $key){
130
+        foreach ((array)$keys as $key) {
131 131
             $cachedItem = $this->cache->get($key);
132 132
             $result[$key] = (null !== $cachedItem) ? $cachedItem : $default;
133 133
         }
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
         $this->_isTraversable($values);
156 156
         $results = [];
157 157
 
158
-        foreach ((array)$values as $key => $value){
158
+        foreach ((array)$values as $key => $value) {
159 159
             $results[] = $this->cache->set($key, $value, $ttl);
160 160
         }
161 161
 
162
-        if ($this->_hasFailure($results)){
162
+        if ($this->_hasFailure($results)) {
163 163
             return false;
164 164
         }
165 165
 
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
         $this->_isTraversable($keys);
183 183
         $results = [];
184 184
 
185
-        foreach ((array)$keys as $key){
185
+        foreach ((array)$keys as $key) {
186 186
             $results[] = $this->cache->delete($key);
187 187
         }
188 188
 
189
-        if ($this->_hasFailure($results)){
189
+        if ($this->_hasFailure($results)) {
190 190
             return false;
191 191
         }
192 192
 
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
      * @param $key
210 210
      * @throws InvalidArgumentException
211 211
      */
212
-    private function _isValidKey($key){
213
-        if (!is_string($key)){
212
+    private function _isValidKey($key) {
213
+        if (!is_string($key)) {
214 214
             throw new InvalidArgumentException('provided key must be a valid string');
215 215
         }
216 216
     }
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
      * @return bool
224 224
      * @internal
225 225
      */
226
-    private function _isTraversable($data){
226
+    private function _isTraversable($data) {
227 227
 
228
-        if (is_array($data) || $data instanceof \Traversable){
228
+        if (is_array($data) || $data instanceof \Traversable) {
229 229
             return true;
230 230
         }
231 231
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      */
240 240
     private function _hasKeys(array $arr)
241 241
     {
242
-        if (array() === $arr || array_keys($arr) === range(0, count($arr) - 1)){
242
+        if (array() === $arr || array_keys($arr) === range(0, count($arr) - 1)) {
243 243
             throw new InvalidArgumentException('Keys missing');
244 244
         }
245 245
 
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
      * @return bool
254 254
      * @internal
255 255
      */
256
-    private function _hasFailure(array $results){
257
-        if (in_array(false, $results)){
256
+    private function _hasFailure(array $results) {
257
+        if (in_array(false, $results)) {
258 258
             return true;
259 259
         }
260 260
         return false;
Please login to merge, or discard this patch.
Tests/Cache/CacheTest.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     {
41 41
         $key = 21021000;
42 42
         $this->expectException(InvalidArgumentException::class);
43
-        $this->cache->set($key,'value');
43
+        $this->cache->set($key, 'value');
44 44
     }
45 45
 
46 46
     /**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     /**
207 207
      *
208 208
      */
209
-    public function testGetMultiple(){
209
+    public function testGetMultiple() {
210 210
 
211 211
         $expected = [
212 212
             'foo' => 'fooValue',
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 
217 217
         $i = 0;
218 218
 
219
-        foreach ($expected as $key => $value){
219
+        foreach ($expected as $key => $value) {
220 220
 
221 221
             $this->storageMock->expects($this->at($i))
222 222
                 ->method('get')
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     /**
237 237
      *
238 238
      */
239
-    public function testSetMultiple(){
239
+    public function testSetMultiple() {
240 240
 
241 241
         $keys = [
242 242
             'foo' => 'fooValue',
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
         $i = 0;
251 251
         $expires = 60 * 60;
252 252
 
253
-        foreach ($keys as $key => $value){
253
+        foreach ($keys as $key => $value) {
254 254
             $this->storageMock->expects($this->at($i))
255 255
                 ->method('set')
256 256
                 ->with(
@@ -262,14 +262,14 @@  discard block
 block discarded – undo
262 262
             $i++;
263 263
         }
264 264
 
265
-        $actual = $this->cache->setMultiple($keys,$expires);
265
+        $actual = $this->cache->setMultiple($keys, $expires);
266 266
         $this->assertEquals($expected, $actual);
267 267
     }
268 268
 
269 269
     /**
270 270
      *
271 271
      */
272
-    public function testSetMultipleWithFailure(){
272
+    public function testSetMultipleWithFailure() {
273 273
 
274 274
         $keys = [
275 275
             'foo' => 'fooValue',
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
         $i = 0;
284 284
         $expires = 60 * 60;
285 285
 
286
-        foreach ($keys as $key => $value){
286
+        foreach ($keys as $key => $value) {
287 287
 
288 288
             $status = $addStatus;
289 289
 
290
-            if ($i === 1){
290
+            if ($i === 1) {
291 291
                 $status = false;
292 292
             }
293 293
 
@@ -302,20 +302,20 @@  discard block
 block discarded – undo
302 302
             $i++;
303 303
         }
304 304
 
305
-        $actual = $this->cache->setMultiple($keys,$expires);
305
+        $actual = $this->cache->setMultiple($keys, $expires);
306 306
         $this->assertEquals($expected, $actual);
307 307
     }
308 308
 
309 309
     /**
310 310
      *
311 311
      */
312
-    public function testDeleteMultiple(){
312
+    public function testDeleteMultiple() {
313 313
 
314
-        $keys = ['foo','bar','baz'];
314
+        $keys = ['foo', 'bar', 'baz'];
315 315
         $deleteStatus = true;
316 316
         $expected = true;
317 317
 
318
-        foreach ($keys as $i => $key){
318
+        foreach ($keys as $i => $key) {
319 319
             $this->storageMock->expects($this->at($i))
320 320
                 ->method('delete')
321 321
                 ->with(
@@ -331,15 +331,15 @@  discard block
 block discarded – undo
331 331
     /**
332 332
      *
333 333
      */
334
-    public function testDeleteMultipleFailure(){
334
+    public function testDeleteMultipleFailure() {
335 335
 
336
-        $keys = ['foo','bar','baz'];
336
+        $keys = ['foo', 'bar', 'baz'];
337 337
         $expected = false;
338 338
         $deleteStatus = true;
339 339
 
340
-        foreach ($keys as $i => $key){
340
+        foreach ($keys as $i => $key) {
341 341
 
342
-            if ($i === 1){
342
+            if ($i === 1) {
343 343
                 $deleteStatus = false;
344 344
             }
345 345
 
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
     /**
359 359
      * Test that storage clear is called.
360 360
      */
361
-    public function testclear(){
361
+    public function testclear() {
362 362
         $this->storageMock->expects($this->once())
363 363
             ->method('clear');
364 364
         $this->cache->clear();
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     /**
368 368
      * Test that array has keys.
369 369
      */
370
-    public function testArrayHasKeys(){
370
+    public function testArrayHasKeys() {
371 371
         $data = ['a' => 'foo', 'b' => 'bar'];
372 372
 
373 373
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
@@ -381,9 +381,9 @@  discard block
 block discarded – undo
381 381
     /**
382 382
      * Test exception thrown when array is missing keys.
383 383
      */
384
-    public function testArrayHasNoKeys(){
384
+    public function testArrayHasNoKeys() {
385 385
         $this->expectException(InvalidArgumentException::class);
386
-        $data = ['foo','bar'];
386
+        $data = ['foo', 'bar'];
387 387
         $reflector = new \ReflectionClass(Cache::class);
388 388
         $method = $reflector->getMethod('_hasKeys');
389 389
         $method->setAccessible(true);
@@ -393,8 +393,8 @@  discard block
 block discarded – undo
393 393
     /**
394 394
      * Test array contains a failure.
395 395
      */
396
-    public function testHasFailure(){
397
-        $results = [true,true,true,false,true];
396
+    public function testHasFailure() {
397
+        $results = [true, true, true, false, true];
398 398
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
399 399
         $method = $reflector->getMethod('_hasFailure');
400 400
         $method->setAccessible(true);
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
     /**
407 407
      *
408 408
      */
409
-    public function testHasNoFailure(){
410
-        $results = [true,true,true,true,true];
409
+    public function testHasNoFailure() {
410
+        $results = [true, true, true, true, true];
411 411
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
412 412
         $method = $reflector->getMethod('_hasFailure');
413 413
         $method->setAccessible(true);
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
     /**
420 420
      * Test that array is Traversable
421 421
      */
422
-    public function testIsTraversable(){
423
-        $data = ['a','b','c','d'];
422
+    public function testIsTraversable() {
423
+        $data = ['a', 'b', 'c', 'd'];
424 424
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
425 425
         $method = $reflector->getMethod('_isTraversable');
426 426
         $method->setAccessible(true);
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     /**
433 433
      * Test that string is not Traversable
434 434
      */
435
-    public function testIsNotTraversable(){
435
+    public function testIsNotTraversable() {
436 436
         $this->expectException(InvalidArgumentException::class);
437 437
         $data = 'some-random-string';
438 438
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     /**
445 445
      * Test that instance of Iterator is traversable
446 446
      */
447
-    public function testIsTraversableIterator(){
447
+    public function testIsTraversableIterator() {
448 448
         $iterator = new IteratorMock();
449 449
         $reflector = new \ReflectionClass('\Ds\Cache\Cache');
450 450
         $method = $reflector->getMethod('_isTraversable');
Please login to merge, or discard this patch.
Tests/Cache/Mock/IteratorMock.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@
 block discarded – undo
9 9
  *
10 10
  * @package Tests\Cache\Mock
11 11
  */
12
-class IteratorMock implements \Iterator{
13
-    public function current(){}
14
-    public function next(){}
15
-    public function key(){}
16
-    public function valid(){}
17
-    public function rewind(){}
12
+class IteratorMock implements \Iterator {
13
+    public function current() {}
14
+    public function next() {}
15
+    public function key() {}
16
+    public function valid() {}
17
+    public function rewind() {}
18 18
 }
Please login to merge, or discard this patch.
Tests/Cache/Mock/AbstractStorageMock.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@
 block discarded – undo
11 11
  *
12 12
  * @package Tests\Cache\Mock
13 13
  */
14
-class AbstractStorageMock extends AbstractStorage{
15
-    public function set($key, $value, $ttl = null){}
16
-    public function has($key){}
17
-    public function get($key){}
18
-    public function delete($key){}
19
-    public function clear(){}
14
+class AbstractStorageMock extends AbstractStorage {
15
+    public function set($key, $value, $ttl = null) {}
16
+    public function has($key) {}
17
+    public function get($key) {}
18
+    public function delete($key) {}
19
+    public function clear() {}
20 20
 }
21 21
\ No newline at end of file
Please login to merge, or discard this patch.