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

DisableCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
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 6
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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 DisableCommand 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:disable')
32
            ->setDescription('Disables 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(false);
58
        $this->manufacturerRepository->flush();
59
    }
60
}
61