ConfigurationFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Service\Configuration;
6
7
use Arp\LaminasDoctrine\Service\Configuration\Exception\ConfigurationFactoryException;
8
use Doctrine\ORM\Configuration;
9
use Laminas\ServiceManager\ServiceLocatorInterface;
10
use Psr\Container\ContainerExceptionInterface;
11
12
/**
13
 * Factory class for the Doctrine Configuration via the Laminas ServiceManager. This is not ideal as we treat the
14
 * manager as a ServiceLocator, however this class is already an abstraction that is used as an implementation detail
15
 * of ConfigurationManager.
16
 */
17
final class ConfigurationFactory implements ConfigurationFactoryInterface
18
{
19
    public function __construct(private readonly ServiceLocatorInterface $serviceManager)
20
    {
21
    }
22
23
    /**
24
     * @param array<string, mixed> $config
25
     *
26
     * @return Configuration
27
     *
28
     * @throws ConfigurationFactoryException
29
     */
30
    public function create(array $config): Configuration
31
    {
32
        try {
33
            return $this->serviceManager->build(Configuration::class, $config);
34
        } catch (ContainerExceptionInterface $e) {
35
            throw new ConfigurationFactoryException(
36
                sprintf('Failed to create ORM Configuration: %s', $e->getMessage()),
37
                $e->getCode(),
38
                $e
39
            );
40
        }
41
    }
42
}
43