DoctrineOrmCommandTrait::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
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\EntityManagerInterface;
9
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
10
use Symfony\Component\Console\Helper\HelperSet;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
trait DoctrineOrmCommandTrait
16
{
17
    /**
18
     * @var ManagerRegistry
19
     */
20
    private $managerRegistry;
21
22 14
    public function __construct(ManagerRegistry $managerRegistry, ?string $name = null)
23
    {
24 14
        parent::__construct($name);
25
26 14
        $this->managerRegistry = $managerRegistry;
27 14
    }
28
29 14
    protected function configure(): void
30
    {
31 14
        parent::configure();
32
33 14
        $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? ( Ignorable by Annotation )

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

33
        $this->/** @scrutinizer ignore-call */ 
34
               addOption(
Loading history...
34 14
            'em',
35 14
            null,
36 14
            InputOption::VALUE_OPTIONAL,
37 14
            'The entity manager to use for this command'
38
        );
39 14
    }
40
41 1
    protected function execute(InputInterface $input, OutputInterface $output): ?int
42
    {
43
        /** @var string|null $name */
44 1
        $name = $input->getOption('em');
45
46
        /** @var EntityManagerInterface $entityManager */
47 1
        $entityManager = $this->managerRegistry->getManager($name);
48
49 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? ( Ignorable by Annotation )

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

49
        $this->/** @scrutinizer ignore-call */ 
50
               setHelperSet(new HelperSet(['em' => new EntityManagerHelper($entityManager)]));
Loading history...
50
51 1
        return parent::execute($input, $output);
52
    }
53
}
54