ConfigurationFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A __construct() 0 2 1
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