Passed
Push — master ( a8ec29...5f73fa )
by Chauncey
08:25
created

PurgeCacheAction::run()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 2
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Charcoal\Admin\Action\System;
4
5
// From PSR-7
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
// From 'charcoal-admin'
10
use Charcoal\Admin\Action\System\AbstractCacheAction;
11
12
/**
13
 * Purge stale or expired items.
14
 */
15
class PurgeCacheAction extends AbstractCacheAction
16
{
17
    /**
18
     * @param  RequestInterface  $request  A PSR-7 compatible Request instance.
19
     * @param  ResponseInterface $response A PSR-7 compatible Response instance.
20
     * @return ResponseInterface
21
     */
22
    public function run(RequestInterface $request, ResponseInterface $response)
23
    {
24
        $cache  = $this->cachePool();
25
        $result = $cache->purge();
0 ignored issues
show
Bug introduced by
The method purge() does not exist on Psr\Cache\CacheItemPoolInterface. It seems like you code against a sub-type of Psr\Cache\CacheItemPoolInterface such as Stash\Interfaces\PoolInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $result = $cache->purge();
Loading history...
26
27
        if ($result) {
28
            $message = $this->translator()->translate('Cache purged successfully.');
29
        } else {
30
            $message = $this->translator()->translate('Failed to purge cache.');
31
        }
32
33
        $this->setSuccess($result);
34
35
        if ($result) {
36
            $this->addFeedback('success', $message);
37
            return $response;
38
        } else {
39
            $this->addFeedback('error', $message);
40
            return $response->withStatus(500);
41
        }
42
    }
43
}
44