EnableCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 95.92 %

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 49
ccs 0
cts 23
cp 0
rs 10

3 Methods

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