GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 66c18c...f0be87 )
by Bram
05:17
created

CacheAllExcept::getExcept()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author Bram Gerritsen [email protected]
4
 * @copyright (c) Bram Gerritsen 2013
5
 * @license http://opensource.org/licenses/mit-license.php
6
 */
7
8
namespace StrokerCache\Strategy;
9
10
use Zend\Mvc\MvcEvent;
11
12
use StrokerCache\Exception\BadConfigurationException;
13
14
class CacheAllExcept extends AbstractStrategy
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $except;
20
21
    /**
22
     * {@inheritDoc}
23
     */
24 21
    public function shouldCache(MvcEvent $event)
25
    {
26 21
        $except = $this->getExcept();
27
28 21
        if (!isset($except['namespaces']) && !isset($except['controllers']) && !isset($except['actions'])) {
29 1
            throw new BadConfigurationException(
30
                  "At least one of ['namespaces', 'controllers', 'actions'] keys has to be set in the "
31 1
                . "\$config['strokercache']['strategies']['enabled']['" . __CLASS__ . "']['except'][] "
32 1
                . "configuration array."
33 1
            );
34
        }
35
36 20
        $routeMatch = $event->getRouteMatch();
37
38 20
        if (null === $routeMatch) {
39 1
            return false;
40
        }
41
42 19
        $controller  = $this->normalize($routeMatch->getParam('controller'));
43 19
        $action      = $this->normalize($routeMatch->getParam('action'));
44
45 19
        $shouldCache = true;
46
47 19
        if (true === $shouldCache && isset($except['namespaces'])) {
48 19
            foreach ($except['namespaces'] as $exceptNamespace) {
49 19
                if (0 === strpos($controller, $this->normalize($exceptNamespace))) {
50 6
                    $shouldCache = false;
51 6
                    break 1;
52
                }
53 19
            }
54 19
        }
55
56 19
        if (true === $shouldCache && isset($except['controllers'])) {
57 13
            foreach ($except['controllers'] as $exceptController) {
58 13
                if ($controller === $this->normalize($exceptController)) {
59 4
                    $shouldCache = false;
60 4
                    break 1;
61
                }
62 13
            }
63 13
        }
64
65 19
        if (true === $shouldCache && isset($except['actions'])) {
66 9
            foreach ($except['actions'] as $exceptController => $exceptActions) {
67 9
                if ($controller === $this->normalize($exceptController)) {
68 4
                    foreach ($exceptActions as $exceptAction) {
69 4
                        if ($action === $this->normalize($exceptAction)) {
70 3
                            $shouldCache = false;
71 3
                            break 2;
72
                        }
73 3
                    }
74 1
                }
75 9
            }
76 9
        }
77
78 19
        return $shouldCache;
79
    }
80
81
    /**
82
     * @return array
83
     */
84 21
    public function getExcept()
85
    {
86 21
        return $this->except;
87
    }
88
89
    /**
90
     * @param array $except
91
     * @return $this
92
     */
93 21
    public function setExcept(array $except)
94
    {
95 21
        $this->except = $except;
96
97 21
        return $this;
98
    }
99
100
    /**
101
     * Normalize names before comparing
102
     *
103
     * @param string $string
104
     * @return string
105
     */
106 19
    protected function normalize($string)
107
    {
108 19
        $string = trim($string);
109
110 19
        $string = strtolower($string);
111
112 19
        return $string;
113
    }
114
}