Completed
Push — master ( 07fc20...4efd3c )
by David de
34:38
created

Tag   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 85
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 3
dl 15
loc 85
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 2
A setValue() 0 4 2
A setExpression() 0 9 2
A getExpression() 0 4 1
A setTags() 0 10 3
A getTags() 0 4 1
A getAliasName() 0 4 1
A allowArray() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 FOS\HttpCacheBundle\Exception\InvalidTagException;
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation;
16
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
17
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
18
19
/**
20
 * @Annotation
21
 */
22
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
23
class Tag extends ConfigurationAnnotation
24
{
25
    private $tags;
26
27
    private $expression;
28
29 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
        $data = [],
31
        $expression = null
32
    ) {
33 11
        $values = [];
34
        if (is_string($data)) {
35 11
            $values['value'] = $data;
36 11
        } else {
37
            $values = $data;
38
        }
39
40
        $values['expression'] = $values['expression'] ?? $expression;
41 3
42
        parent::__construct($values);
43
    }
44
45
    /**
46
     * Handle tags given without explicit key.
47
     *
48 3
     * @param string|array $data
49 3
     */
50
    public function setValue($data)
51
    {
52
        $this->setTags(is_array($data) ? $data : [$data]);
53
    }
54 11
55
    /**
56 11
     * @param mixed $expression
57
     */
58
    public function setExpression($expression)
59 12
    {
60
        // @codeCoverageIgnoreStart
61 12
        if (!class_exists(ExpressionLanguage::class)) {
62 12
            throw new InvalidConfigurationException('@Tag param uses an expression but the ExpressionLanguage is not available.');
63 1
        }
64
        // @codeCoverageIgnoreEnd
65
        $this->expression = $expression;
66
    }
67 11
68 11
    /**
69
     * @return mixed
70 9
     */
71
    public function getExpression()
72 9
    {
73
        return $this->expression;
74
    }
75
76
    public function setTags(array $tags)
77
    {
78 4
        foreach ($tags as $tag) {
79
            if (false !== \strpos($tag, ',')) {
80 4
                throw new InvalidTagException($tag, ',');
81
            }
82
        }
83
84
        $this->tags = $tags;
85
    }
86 4
87
    public function getTags()
88 4
    {
89
        return $this->tags;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function getAliasName()
96
    {
97
        return 'tag';
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function allowArray()
104
    {
105
        return true;
106
    }
107
}
108