Completed
Pull Request — master (#299)
by David
67:30 queued 64:42
created

RefreshPathCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 4
c 2
b 2
f 0
lcom 1
cbo 4
dl 56
loc 56
ccs 21
cts 21
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A configure() 20 20 1
A execute() 8 8 2

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\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Input\InputArgument;
17
use FOS\HttpCacheBundle\CacheManager;
18
19
/**
20
 * A command to trigger cache refresh by path from the command line.
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24 View Code Duplication
class RefreshPathCommand extends BaseInvalidateCommand
25
{
26
    /**
27
     * @var string
28
     */
29
    private $commandName;
30
31
    /**
32
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
33
     * is automatically loaded.
34
     *
35
     * @param CacheManager|null $cacheManager The cache manager to talk to.
36
     * @param string            $commandName  Name of this command, in case you want to reuse it.
37
     */
38 10
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:refresh:path')
39
    {
40 10
        $this->commandName = $commandName;
41 10
        parent::__construct($cacheManager);
42 10
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 10
    protected function configure()
48
    {
49 10
        $this
50 10
            ->setName($this->commandName)
51 10
            ->setDescription('Refresh paths on all configured caching proxies')
52 10
            ->addArgument(
53 10
                'paths',
54 10
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
55
                'URL paths you want to refresh, you can specify any number of paths'
56 10
            )
57 10
            ->setHelp(<<<'EOF'
58
The <info>%command.name%</info> command refreshes a list of paths on the configured caching proxies.
59
60
Example:
61
62
    <info>php %command.full_name% /some/path /other/path</info>
63
EOF
64 10
            )
65
        ;
66 10
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 3
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73 3
        $paths = $input->getArgument('paths');
74
75 3
        foreach ($paths as $path) {
76 3
            $this->getCacheManager()->refreshPath($path);
77 3
        }
78 3
    }
79
}
80