Completed
Push — master ( 511f14...1430f7 )
by Joachim
02:13
created

EnableCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 4
dl 47
loc 47
ccs 0
cts 22
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A configure() 8 8 1
A execute() 15 15 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 Loevgaard\DandomainConsignmentBundle\Command;
4
5
use Doctrine\ORM\OptimisticLockException;
6
use Doctrine\ORM\ORMException;
7
use Loevgaard\DandomainConsignmentBundle\Exception\NonExistentManufacturerException;
8
use Loevgaard\DandomainFoundation\Repository\ManufacturerRepository;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14 View Code Duplication
class EnableCommand extends ContainerAwareCommand
0 ignored issues
show
Duplication introduced by
This class 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...
15
{
16
    /**
17
     * @var ManufacturerRepository
18
     */
19
    protected $manufacturerRepository;
20
21
    public function __construct(ManufacturerRepository $manufacturerRepository)
22
    {
23
        $this->manufacturerRepository = $manufacturerRepository;
24
25
        parent::__construct();
26
    }
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('loevgaard:dandomain-consignment:enable')
32
            ->setDescription('Enables consignment for the specified manufacturer')
33
            ->addArgument('manufacturer', InputArgument::REQUIRED, 'The manufacturer')
34
        ;
35
    }
36
37
    /**
38
     * @param InputInterface $input
39
     * @param OutputInterface $output
40
     * @return int|null|void
41
     * @throws NonExistentManufacturerException
42
     * @throws ORMException
43
     * @throws OptimisticLockException
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        // fetch arguments and options
48
        $manufacturer = $input->getArgument('manufacturer');
49
50
        // find manufacturer
51
        $manufacturer = $this->manufacturerRepository->findOneByExternalId($manufacturer);
52
53
        if (!$manufacturer) {
54
            throw new NonExistentManufacturerException('The manufacturer does not exist');
55
        }
56
57
        $manufacturer->setConsignment(true);
58
        $this->manufacturerRepository->flush();
59
    }
60
}
61