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   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 4
Metric Value
wmc 22
c 7
b 2
f 4
lcom 1
cbo 4
dl 0
loc 101
ccs 48
cts 48
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getExcept() 0 4 1
C shouldCache() 0 56 19
A setExcept() 0 6 1
A normalize() 0 8 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
}