EnableCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
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