AbstractCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 63
ccs 17
cts 18
cp 0.9444
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getManager() 0 3 1
A execute() 0 17 2
A configure() 0 6 1
1
<?php
2
3
namespace Terox\SubscriptionBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Terox\SubscriptionBundle\Model\SubscriptionInterface;
10
use Terox\SubscriptionBundle\Subscription\SubscriptionManager;
11
12
abstract class AbstractCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated: since Symfony 4.2, use {@see Command} instead. ( Ignorable by Annotation )

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

12
abstract class AbstractCommand extends /** @scrutinizer ignore-deprecated */ ContainerAwareCommand
Loading history...
13
{
14
    /**
15
     * @var InputInterface
16
     */
17
    protected $input;
18
19
    /**
20
     * @var OutputInterface
21
     */
22
    protected $output;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    protected function configure()
28
    {
29 3
        $this->addArgument(
30 3
            'id',
31 3
            InputArgument::REQUIRED,
32 3
            'Subscription ID'
33
        );
34 3
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        // Save the input interfaces
42 3
        $this->input  = $input;
43 3
        $this->output = $output;
44
45 3
        $subscriptionId = $input->getArgument('id');
46 3
        $subscription   = $this->getContainer()->get('terox.subscription.repository.subscription')->findById($subscriptionId);
47
48 3
        if(null === $subscription) {
49
            return $output->writeln(sprintf('<error>The subscription with ID "%s" was not found.</error>', $subscriptionId));
0 ignored issues
show
Bug introduced by
It seems like $subscriptionId 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

49
            return $output->writeln(sprintf('<error>The subscription with ID "%s" was not found.</error>', /** @scrutinizer ignore-type */ $subscriptionId));
Loading history...
50
        }
51
52
        // Execute the action
53 3
        $this->action($subscription);
54
55 3
        $output->writeln('<green>Finished.</green>');
56 3
    }
57
58
    /**
59
     * Action to execute when
60
     *
61
     * @param SubscriptionInterface $subscription
62
     *
63
     * @return void
64
     */
65
    abstract protected function action(SubscriptionInterface $subscription);
66
67
    /**
68
     * Get SubscriptionManager.
69
     *
70
     * @return SubscriptionManager
71
     */
72 3
    protected function getManager()
73
    {
74 3
        return $this->getContainer()->get('terox.subscription.manager');
75
    }
76
}
77