CreateFeatureCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
ccs 15
cts 15
cp 1
crap 1
rs 9.7666
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 create a feature.
15
 *
16
 * @author Emanuele Minotto <[email protected]>
17
 */
18
class CreateFeatureCommand 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:create')
47 2
            ->setDescription('Create a new feature')
48 2
            ->addArgument('parent', InputArgument::REQUIRED, 'Parent feature')
49 2
            ->addArgument('name', InputArgument::REQUIRED, 'Feature name')
50 2
            ->addOption(
51 2
                'enabled',
52 2
                null,
53 2
                InputOption::VALUE_NONE,
54 2
                'The feature will be created as enabled'
55
            )
56 2
            ->addOption(
57 2
                'role',
58 2
                null,
59 2
                InputOption::VALUE_REQUIRED,
60 2
                'The feature will be only for a role'
61
            );
62 2
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 2
    public function execute(InputInterface $input, OutputInterface $output)
68
    {
69 2
        $name = $input->getArgument('name');
70 2
        $parent = $input->getArgument('parent');
71
72 2
        $output->write(sprintf(
73 2
            'Creating <info>%s</info>.<info>%s</info>... ',
74 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

74
            /** @scrutinizer ignore-type */ $parent,
Loading history...
75 2
            $name
76
        ));
77
78 2
        $feature = $this->featureManager->findOrCreate($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\...Manager::findOrCreate() 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

78
        $feature = $this->featureManager->findOrCreate(/** @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\...Manager::findOrCreate() 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

78
        $feature = $this->featureManager->findOrCreate($name, /** @scrutinizer ignore-type */ $parent);
Loading history...
79
80 2
        $feature->setEnabled($input->getOption('enabled'));
81 2
        $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

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

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

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