Completed
Push — master ( 4758e8...ddc8c1 )
by David de
03:36
created

InvalidateRoute::setParams()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 9.3554

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 7
cts 11
cp 0.6364
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 15
nc 6
nop 1
crap 9.3554
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Configuration;
13
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
15
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
16
17
/**
18
 * @Annotation
19
 */
20
class InvalidateRoute extends ConfigurationAnnotation
21
{
22
    /**
23
     * @var string
24
     */
25
    private $name;
26
27
    /**
28
     * @var array
29
     */
30
    private $params;
31
32
    /**
33
     * Handle route name given without explicit key.
34
     *
35
     * @param string $value The route name
36
     */
37 1
    public function setValue($value)
38
    {
39 1
        $this->setName($value);
40 1
    }
41
42
    /**
43
     * @param string $name
44
     */
45 1
    public function setName($name)
46
    {
47 1
        $this->name = $name;
48 1
    }
49
50
    /**
51
     * @return string
52
     */
53 1
    public function getName()
54
    {
55 1
        return $this->name;
56
    }
57
58
    /**
59
     * @param array $params
60
     */
61 1
    public function setParams($params)
62
    {
63 1
        if (!is_array($params)) {
64
            throw new \RuntimeException('InvalidateRoute params must be an array');
65
        }
66 1
        foreach ($params as $name => $value) {
67 1
            if (is_array($value)) {
68 1
                if (1 !== count($value) || !isset($value['expression'])) {
69
                    throw new \RuntimeException(sprintf(
70
                        '@InvalidateRoute param %s must be string or {"expression"="<expression>"}',
71
                        $name,
72
                        print_r($value, true)
73
                    ));
74
                }
75
                // @codeCoverageIgnoreStart
76
                if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
77
                    throw new InvalidConfigurationException(sprintf(
78
                        '@InvalidateRoute param %s uses an expression but the ExpressionLanguage is not available.',
79
                        $name
80
                    ));
81
                }
82
                // @codeCoverageIgnoreEnd
83
            }
84
        }
85
86 1
        $this->params = $params;
87 1
    }
88
89
    /**
90
     * @return array
91
     */
92 1
    public function getParams()
93
    {
94 1
        return $this->params;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 1
    public function getAliasName()
101
    {
102 1
        return 'invalidate_route';
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 1
    public function allowArray()
109
    {
110 1
        return true;
111
    }
112
}
113