AntidotCliDoctrineDelegatorFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 20
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 31
ccs 19
cts 19
cp 1
crap 2
rs 9.6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Persistence\Doctrine\Container;
6
7
use Antidot\Cli\Application\Console;
8
use Psr\Container\ContainerInterface;
9
use Symfony\Component\Console\Helper\QuestionHelper;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
13
class AntidotCliDoctrineDelegatorFactory
14
{
15 1
    public function __invoke(ContainerInterface $container, string $name, callable $callback): Console
16
    {
17
        /** @var Console $console */
18 1
        $console = $callback();
19 1
        $definition = $console->getDefinition();
20 1
        $definition->addOption(new InputOption(
21 1
            'connection',
22 1
            'c',
23 1
            InputArgument::OPTIONAL,
24 1
            'Doctrine connection name.',
25 1
            'orm_default'
26
        ));
27 1
        $input = $console->getInput();
28
        try {
29 1
            $input->bind($definition);
30 1
        } catch (\Throwable $e) {
31
            // Errors must be ignored, full binding/validation happens later when the command is known.
32
        }
33
34
        /** @var string $connection */
35 1
        $connection = $input->getOption('connection') ?? 'orm_default';
36 1
        $console->setHelperSet((new DoctrineCliHelperSetFactory())->__invoke(
37 1
            $container,
38
            $connection
39
        ));
40
41 1
        $helperSet = $console->getHelperSet();
42 1
        $helperSet->set(new QuestionHelper(), 'question');
43 1
        $console->setHelperSet($helperSet);
44
45 1
        return $console;
46
    }
47
}
48