RestoreCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 84 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 21
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 9 9 1
A executeConfigured() 12 12 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
namespace Storeman\Cli\Command;
4
5
use Storeman\Storeman;
6
use Storeman\Cli\SynchronizationProgressListener;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class RestoreCommand extends AbstractCommand
12
{
13 View Code Duplication
    protected function configure()
14
    {
15
        parent::configure();
16
17
        $this->setName('restore');
18
        $this->setDescription('Restores the local state from the vault state.');
19
        $this->addOption('revision', 'r', InputOption::VALUE_REQUIRED, 'Restore given revision. Defaults to last revision.');
20
        $this->addOption('vault', null, InputOption::VALUE_REQUIRED, 'Vault to use to download state from.');
21
    }
22
23 View Code Duplication
    protected function executeConfigured(InputInterface $input, OutputInterface $output, Storeman $storeman): int
24
    {
25
        $storeman->restore(
26
            $input->getOption('revision') ? (int)$input->getOption('revision') : null,
27
            $input->getOption('vault'),
28
            new SynchronizationProgressListener($output)
29
        );
30
31
        $output->writeln(PHP_EOL . '<info>Done!</info>');
32
33
        return 0;
34
    }
35
}
36