EnableFeatureCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
ccs 10
cts 10
cp 1
crap 1
rs 9.9332
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\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Command used to enable an existing feature.
15
 *
16
 * @author Emanuele Minotto <[email protected]>
17
 */
18
class EnableFeatureCommand extends Command
19
{
20
    /**
21
     * @var FeatureManager
22
     */
23
    private $featureManager;
24
25
    /**
26
     * @var EntityManager
27
     */
28
    private $entityManager;
29
30 2
    public function __construct(
31
        FeatureManager $featureManager,
32
        EntityManager $entityManager
33
    ) {
34 2
        parent::__construct();
35
36 2
        $this->featureManager = $featureManager;
37 2
        $this->entityManager = $entityManager;
38 2
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    protected function configure()
44
    {
45
        $this
46 2
            ->setName('features:enable')
47 2
            ->setDescription('Enable an existing feature')
48 2
            ->addArgument('parent', InputArgument::REQUIRED, 'Parent feature')
49 2
            ->addArgument('name', InputArgument::REQUIRED, 'Feature name')
50 2
            ->addOption(
51 2
                'role',
52 2
                null,
53 2
                InputOption::VALUE_REQUIRED,
54 2
                'The feature will be only for a role'
55
            );
56 2
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 2
    public function execute(InputInterface $input, OutputInterface $output)
62
    {
63 2
        $name = $input->getArgument('name');
64 2
        $parent = $input->getArgument('parent');
65
66 2
        $output->write(sprintf(
67 2
            'Enabling <info>%s</info>.<info>%s</info>... ',
68 2
            $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

68
            /** @scrutinizer ignore-type */ $parent,
Loading history...
69 2
            $name
70
        ));
71
72 2
        $feature = $this->featureManager->find($name, $parent);
0 ignored issues
show
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

72
        $feature = $this->featureManager->find($name, /** @scrutinizer ignore-type */ $parent);
Loading history...
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

72
        $feature = $this->featureManager->find(/** @scrutinizer ignore-type */ $name, $parent);
Loading history...
73
74 2
        $feature->setEnabled(true);
75
76 2
        if (null !== $input->getOption('role')) {
77 1
            $feature->setRole($input->getOption('role'));
0 ignored issues
show
Bug introduced by
It seems like $input->getOption('role') can also be of type string[]; however, parameter $role of Ae\FeatureBundle\Entity\Feature::setRole() 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

77
            $feature->setRole(/** @scrutinizer ignore-type */ $input->getOption('role'));
Loading history...
78
        }
79
80 2
        $this->entityManager->persist($feature);
81 2
        $this->entityManager->flush();
82
83 2
        $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

83
        $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

83
        $this->featureManager->emptyCache($name, /** @scrutinizer ignore-type */ $parent);
Loading history...
84
85 2
        $output->writeln('OK');
86
87 2
        return 0;
88
    }
89
}
90