DelegateCommand::wrapCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.9
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;
4
5
use RuntimeException;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Command Delegate.
13
 */
14
abstract class DelegateCommand extends Command
15
{
16
    /** @var Command */
17
    protected $command;
18
19
    /**
20
     * @return Command
21
     */
22
    abstract protected function createCommand();
23
24
    /**
25
     * @return string
26
     */
27
    protected function getMinimalVersion()
28
    {
29
        return '2.3.0-DEV';
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function isEnabled()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
    {
37
        return $this->isVersionCompatible();
0 ignored issues
show
Bug introduced by
The method isVersionCompatible() does not seem to exist on object<Doctrine\Bundle\D...\Proxy\DelegateCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
    }
39
40
    /**
41
     * @param string $entityManagerName
42
     *
43
     * @return Command
44
     */
45
    protected function wrapCommand($entityManagerName)
46
    {
47
        if (! $this->isVersionCompatible()) {
0 ignored issues
show
Bug introduced by
The method isVersionCompatible() does not seem to exist on object<Doctrine\Bundle\D...\Proxy\DelegateCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
            throw new RuntimeException(sprintf('"%s" requires doctrine-orm "%s" or newer', $this->getName(), $this->getMinimalVersion()));
49
        }
50
51
        DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $entityManagerName);
0 ignored issues
show
Documentation introduced by
$this->getApplication() is of type null|object<Symfony\Comp...nt\Console\Application>, but the function expects a object<Symfony\Bundle\Fr...le\Console\Application>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
        $this->command->setApplication($this->getApplication());
53
54
        return $this->command;
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    protected function configure()
61
    {
62
        if ($this->isVersionCompatible()) {
0 ignored issues
show
Bug introduced by
The method isVersionCompatible() does not seem to exist on object<Doctrine\Bundle\D...\Proxy\DelegateCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            $this->command = $this->createCommand();
64
65
            $this->setHelp($this->command->getHelp());
66
            $this->setDefinition($this->command->getDefinition());
67
            $this->setDescription($this->command->getDescription());
68
        }
69
70
        $this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    protected function execute(InputInterface $input, OutputInterface $output)
77
    {
78
        return $this->wrapCommand($input->getOption('em'))->execute($input, $output);
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    protected function interact(InputInterface $input, OutputInterface $output)
85
    {
86
        $this->wrapCommand($input->getOption('em'))->interact($input, $output);
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    protected function initialize(InputInterface $input, OutputInterface $output)
93
    {
94
        $this->wrapCommand($input->getOption('em'))->initialize($input, $output);
95
    }
96
}
97