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
![]() |
|||||||
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
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
![]() |
|||||||
50 | |||||||
51 | 1 | return parent::execute($input, $output); |
|||||
52 | } |
||||||
53 | } |
||||||
54 |