Passed
Push — master ( a0bf27...82f62e )
by Dominik
03:28
created

DoctrineOrmCommandTrait::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\DoctrineDbServiceProvider\Command\Orm;
6
7
use Doctrine\Common\Persistence\ManagerRegistry;
8
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
9
use Symfony\Component\Console\Helper\HelperSet;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
trait DoctrineOrmCommandTrait
15
{
16
    /**
17
     * @var ManagerRegistry
18
     */
19
    private $managerRegistry;
20
21
    /**
22
     * @param ManagerRegistry $managerRegistry
23
     */
24 1
    public function __construct(ManagerRegistry $managerRegistry)
25
    {
26 1
        parent::__construct();
27
28 1
        $this->managerRegistry = $managerRegistry;
29 1
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    protected function configure()
35
    {
36 1
        parent::configure();
37
38 1
        $this->addOption(
0 ignored issues
show
Bug introduced by
It seems like addOption() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39 1
            'em',
40 1
            null,
41 1
            InputOption::VALUE_OPTIONAL,
42 1
            'The entity manager to use for this command'
43
        );
44 1
    }
45
46
    /**
47
     * @param InputInterface  $input
48
     * @param OutputInterface $output
49
     */
50 1
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52 1
        $name = $input->getOption('em');
53
54 1
        $entityManager = $this->managerRegistry->getManager($name);
55
56 1
        $this->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($entityManager)]));
0 ignored issues
show
Bug introduced by
It seems like setHelperSet() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
57
58 1
        return parent::execute($input, $output);
59
    }
60
}
61