AntidotCliDoctrineDelegatorFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
c 1
b 0
f 1
dl 0
loc 33
ccs 19
cts 19
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 31 2
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