DisableFeatureCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Ae\FeatureBundle\Command;
4
5
use Ae\FeatureBundle\Entity\FeatureManager;
6
use Doctrine\ORM\EntityManager;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Command used to disable an existing feature.
14
 *
15
 * @author Emanuele Minotto <[email protected]>
16
 */
17
class DisableFeatureCommand extends Command
18
{
19
    /**
20
     * @var FeatureManager
21
     */
22
    private $featureManager;
23
24
    /**
25
     * @var EntityManager
26
     */
27
    private $entityManager;
28
29 1
    public function __construct(
30
        FeatureManager $featureManager,
31
        EntityManager $entityManager
32
    ) {
33 1
        parent::__construct();
34
35 1
        $this->featureManager = $featureManager;
36 1
        $this->entityManager = $entityManager;
37 1
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    protected function configure()
43
    {
44
        $this
45 1
            ->setName('features:disable')
46 1
            ->setDescription('Disable an existing feature')
47 1
            ->addArgument('parent', InputArgument::REQUIRED, 'Parent feature')
48 1
            ->addArgument('name', InputArgument::REQUIRED, 'Feature name');
49 1
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function execute(InputInterface $input, OutputInterface $output)
55
    {
56 1
        $name = $input->getArgument('name');
57 1
        $parent = $input->getArgument('parent');
58
59 1
        $output->write(sprintf(
60 1
            'Disabling <info>%s</info>.<info>%s</info>... ',
61 1
            $parent,
0 ignored issues
show
Bug introduced by
It seems like $parent can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
            /** @scrutinizer ignore-type */ $parent,
Loading history...
62 1
            $name
63
        ));
64
65 1
        $feature = $this->featureManager->find($name, $parent);
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type string[]; however, parameter $name of Ae\FeatureBundle\Entity\FeatureManager::find() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $feature = $this->featureManager->find(/** @scrutinizer ignore-type */ $name, $parent);
Loading history...
Bug introduced by
It seems like $parent can also be of type string[]; however, parameter $parent of Ae\FeatureBundle\Entity\FeatureManager::find() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $feature = $this->featureManager->find($name, /** @scrutinizer ignore-type */ $parent);
Loading history...
66
67 1
        $feature->setEnabled(false);
68
69 1
        $this->entityManager->persist($feature);
70 1
        $this->entityManager->flush();
71
72 1
        $this->featureManager->emptyCache($name, $parent);
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type string[]; however, parameter $name of Ae\FeatureBundle\Entity\...reManager::emptyCache() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $this->featureManager->emptyCache(/** @scrutinizer ignore-type */ $name, $parent);
Loading history...
Bug introduced by
It seems like $parent can also be of type string[]; however, parameter $parent of Ae\FeatureBundle\Entity\...reManager::emptyCache() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $this->featureManager->emptyCache($name, /** @scrutinizer ignore-type */ $parent);
Loading history...
73
74 1
        $output->writeln('OK');
75
76 1
        return 0;
77
    }
78
}
79