DoctrineCliHelperSetFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\Persistence\Doctrine\Container;
6
7
use Antidot\Persistence\Doctrine\Container\Config\ConfigProvider;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\Tools\Console\ConsoleRunner;
10
use Psr\Container\ContainerInterface;
11
use RuntimeException;
12
use Symfony\Component\Console\Helper\HelperSet;
13
14
class DoctrineCliHelperSetFactory
15
{
16 4
    public function __invoke(
17
        ContainerInterface $container,
18
        string $connectionName = ConfigProvider::DEFAULT_CONNECTION
19
    ): HelperSet {
20 4
        $entityManager = $container->get(sprintf(ConfigProvider::CONNECTION_ALIAS_PATTERN, $connectionName));
21
22 4
        if (false === $entityManager instanceof EntityManagerInterface) {
23 1
            throw new RuntimeException(sprintf(
24 1
                ConfigProvider::CONTAINER_EXCEPTION_MESSAGE_PATTERN,
25 1
                EntityManagerInterface::class
26
            ));
27
        }
28
29 3
        return ConsoleRunner::createHelperSet($entityManager);
30
    }
31
}
32