SymfonyResponseTagger   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A tagSymfonyResponse() 0 18 5
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 bool $replace Whether to replace the current tags on the
23
     *                      response. If false, parses the header to merge
24
     *                      tags
25
     *
26
     * @return $this
27
     */
28
    public function tagSymfonyResponse(Response $response, $replace = false)
29 14
    {
30
        if (!$this->hasTags()) {
31 14
            return $this;
32 4
        }
33
34
        if (!$replace && $response->headers->has($this->getTagsHeaderName())) {
35 10
            $header = $response->headers->get($this->getTagsHeaderName());
36 1
            if ('' !== $header) {
37 1
                $this->addTags(explode(',', $response->headers->get($this->getTagsHeaderName())));
38 1
            }
39
        }
40
41
        $response->headers->set($this->getTagsHeaderName(), $this->getTagsHeaderValue());
42 10
        $this->clear();
43 10
44
        return $this;
45 10
    }
46
}
47