CleanCommand::execute()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 27
rs 8.5806
cc 4
eloc 14
nc 4
nop 2
1
<?php
2
3
namespace Joli\JoliCi\Command;
4
5
use Joli\JoliCi\Container;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class CleanCommand extends Command
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 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...
17
    {
18
        $this->setName('clean');
19
        $this->setDescription('Clean images, containers and/or directories of previous build for this project');
20
        $this->addOption('project-path', 'p', InputOption::VALUE_OPTIONAL, "Path where you project is (default to current directory)", ".");
21
        $this->addOption('keep', 'k', InputOption::VALUE_OPTIONAL, "Number of images / containers / directories per build to keep", 1);
22
        $this->addOption('only-containers', null, InputOption::VALUE_NONE, "Only clean containers (no images or directories)");
23
        $this->addOption('only-directories', null, InputOption::VALUE_NONE, "Only clean directories (no images or containers)");
24
        $this->addOption('only-images', null, InputOption::VALUE_NONE, "Only clean images (no containers or directories), be aware that this may fail if containers are still attached to images (you may need to use force option)");
25
        $this->addOption('force', null, InputOption::VALUE_NONE, "Force removal for images");
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $container = new Container();
34
        $vacuum = $container->getVacuum();
35
36
        if ($input->getOption('only-containers')) {
37
            $vacuum->cleanContainers($vacuum->getJobsToRemove($input->getOption('project-path'), $input->getOption('keep')));
38
39
            return 0;
40
        }
41
42
        if ($input->getOption('only-directories')) {
43
            $vacuum->cleanDirectories($vacuum->getJobsToRemove($input->getOption('project-path'), $input->getOption('keep')));
44
45
            return 0;
46
        }
47
48
        if ($input->getOption('only-images')) {
49
            $vacuum->cleanImages($vacuum->getJobsToRemove($input->getOption('project-path'), $input->getOption('keep')), $input->getOption('force'));
50
51
            return 0;
52
        }
53
54
        $vacuum->clean($input->getOption('project-path'), $input->getOption('keep'), $input->getOption('force'));
55
56
        return 0;
57
    }
58
}
59