Completed
Push — symfony-console ( c96862...f4655c )
by Arnaud
02:14
created

CommandClean   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 26.83 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 8
dl 11
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 11 19 4

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
namespace Cecil\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputDefinition;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class CommandClean extends Command
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('clean')
19
            ->setDescription('Remove the output directory')
20
            ->setDefinition(
21
                new InputDefinition([
22
                    new InputArgument('path', InputArgument::OPTIONAL, 'If specified, use the given path as working directory'),
23
                ])
24
            )
25
            ->setHelp('Remove the output directory and temporary files.');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $outputDir = $this->getBuilder($output)->getConfig()->get('output.dir');
34 View Code Duplication
        if ($this->fs->exists($this->getPath() . '/' . Serve::$tmpDir . '/output')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
35
            $outputDir = file_get_contents($this->getPath() . '/' . Serve::$tmpDir . '/output');
36
        }
37
        // delete output dir
38 View Code Duplication
        if ($this->fs->exists($this->getPath() . '/' . $outputDir)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
39
            $this->fs->remove($this->getPath() . '/' . $outputDir);
40
            $output->writeln(sprintf("Output directory '%s' removed.", $outputDir));
41
        }
42
        // delete local server temp files
43 View Code Duplication
        if ($this->fs->exists($this->getPath() . '/' . Serve::$tmpDir)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
44
            $this->fs->remove($this->getPath() . '/' . Serve::$tmpDir);
45
            $output->writeln('Temporary files deleted.');
46
        }
47
48
        return 0;
49
    }
50
}
51