Completed
Push — master ( 380539...8dc005 )
by David
11:18
created

InvalidatePathCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 62
loc 62
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A configure() 20 20 1
A execute() 12 12 3

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