Completed
Pull Request — master (#235)
by David
03:36
created

SymfonyResponseTagger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 6
loc 30
ccs 6
cts 9
cp 0.6667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B tagSymfonyResponse() 6 17 5

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\Http;
13
14
use FOS\HttpCache\ResponseTagger;
15
use Symfony\Component\HttpFoundation\Response;
16
17
class SymfonyResponseTagger extends ResponseTagger
18
{
19
    /**
20
     * Tag a symfony response with the previously added tags.
21
     *
22
     * @param Response $response
23
     * @param bool     $replace  Whether to replace the current tags on the
24
     *                           response. If false, parses the header to merge
25
     *                           tags
26
     *
27
     * @return $this
28
     */
29 7
    public function tagSymfonyResponse(Response $response, $replace = false)
30
    {
31 7
        if (!$this->hasTags()) {
32 2
            return $this;
33
        }
34
35 5 View Code Duplication
        if (!$replace && $response->headers->has($this->getTagsHeaderName())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
            $header = $response->headers->get($this->getTagsHeaderName());
37
            if ('' !== $header) {
38
                $this->addTags(explode(',', $response->headers->get($this->getTagsHeaderName())));
39
            }
40
        }
41
42 5
        $response->headers->set($this->getTagsHeaderName(), $this->getTagsHeaderValue());
43
44 5
        return $this;
45
    }
46
}
47