Completed
Pull Request — master (#364)
by Alessandro
04:31
created

Symfony   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 7
loc 35
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A purge() 0 6 1
A refresh() 7 7 1
A configureOptions() 0 9 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 FOSHttpCache 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\HttpCache\ProxyClient;
13
14
use FOS\HttpCache\ProxyClient\Invalidation\PurgeCapable;
15
use FOS\HttpCache\ProxyClient\Invalidation\RefreshCapable;
16
use FOS\HttpCache\SymfonyCache\PurgeListener;
17
18
/**
19
 * Symfony HttpCache invalidator.
20
 *
21
 * Additional constructor options:
22
 * - purge_method:         HTTP method that identifies purge requests.
23
 *
24
 * @author David de Boer <[email protected]>
25
 * @author David Buchmann <[email protected]>
26
 */
27
class Symfony extends HttpProxyClient implements PurgeCapable, RefreshCapable
28
{
29
    const HTTP_METHOD_REFRESH = 'GET';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function purge($url, array $headers = [])
35
    {
36
        $this->queueRequest($this->options['purge_method'], $url, $headers);
37
38
        return $this;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 View Code Duplication
    public function refresh($url, array $headers = [])
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...
45
    {
46
        $headers = array_merge($headers, ['Cache-Control' => 'no-cache']);
47
        $this->queueRequest(self::HTTP_METHOD_REFRESH, $url, $headers);
48
49
        return $this;
50
    }
51
52
    protected function configureOptions()
53
    {
54
        $resolver = parent::configureOptions();
55
        $resolver->setDefaults([
56
            'purge_method' => PurgeListener::DEFAULT_PURGE_METHOD,
57
        ]);
58
59
        return $resolver;
60
    }
61
}
62