Completed
Push — 2.0 ( 67fc8b...20321d )
by Lukas Kahwe
13s
created

RemoveCacheCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Command;
13
14
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class RemoveCacheCommand extends Command
22
{
23
    /* @var CacheManager cacheManager */
24
    private $cacheManager;
25
26
    public function __construct(CacheManager $cacheManager)
27
    {
28
        $this->cacheManager = $cacheManager;
29
30
        parent::__construct('liip:imagine:cache:remove');
31
    }
32
33 View Code Duplication
    protected function configure()
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...
34
    {
35
        $this
36
            ->setDescription('Remove cache for given paths and set of filters.')
37
            ->addArgument('paths', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Image paths')
38
            ->addOption(
39
                'filters',
40
                'f',
41
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
42
                'Filters list'
43
            )
44
            ->setHelp(<<<'EOF'
45
The <info>%command.name%</info> command removes cache by specified parameters.
46
47
Paths should be separated by spaces:
48
<info>php app/console %command.name% path1 path2</info>
49
All cache for a given `paths` will be lost.
50
51
If you use --filters parameter:
52
<info>php app/console %command.name% --filters=thumb1 --filters=thumb2</info>
53
All cache for a given filters will be lost.
54
55
You can combine these parameters:
56
<info>php app/console %command.name% path1 path2 --filters=thumb1 --filters=thumb2</info>
57
58
<info>php app/console %command.name%</info>
59
Cache for all paths and filters will be lost when executing this command without parameters.
60
EOF
61
            );
62
    }
63
64
    protected function execute(InputInterface $input, OutputInterface $output)
65
    {
66
        $paths = $input->getArgument('paths');
67
        $filters = $input->getOption('filters');
68
69
        if (empty($filters)) {
70
            $filters = null;
71
        }
72
73
        $this->cacheManager->remove($paths, $filters);
74
    }
75
}
76