Passed
Pull Request — master (#2)
by Alex
02:59
created

ConfigurationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 31
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A __construct() 0 3 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
 * @author  Alex Patterson <[email protected]>
18
 * @package Arp\LaminasDoctrine\Service\Configuration
19
 */
20
final class ConfigurationFactory implements ConfigurationFactoryInterface
21
{
22
    /**
23
     * @var ServiceLocatorInterface
24
     */
25
    private ServiceLocatorInterface $serviceManager;
26
27
    /**
28
     * @param ServiceLocatorInterface $serviceManager
29
     */
30
    public function __construct(ServiceLocatorInterface $serviceManager)
31
    {
32
        $this->serviceManager = $serviceManager;
33
    }
34
35
    /**
36
     * @param array<string, mixed> $config
37
     *
38
     * @return Configuration
39
     *
40
     * @throws ConfigurationFactoryException
41
     */
42
    public function create(array $config): Configuration
43
    {
44
        try {
45
            return $this->serviceManager->build(Configuration::class, $config);
46
        } catch (ContainerExceptionInterface $e) {
47
            throw new ConfigurationFactoryException(
48
                sprintf('Failed to create ORM Configuration: %s', $e->getMessage()),
0 ignored issues
show
Bug introduced by
The method getMessage() does not exist on Psr\Container\ContainerExceptionInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Psr\Container\NotFoundExceptionInterface or Interop\Container\Exception\ContainerException or Interop\Container\Exception\NotFoundException or Interop\Container\Exception\NotFoundException or Laminas\ServiceManager\E...tion\ExceptionInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
                sprintf('Failed to create ORM Configuration: %s', $e->/** @scrutinizer ignore-call */ getMessage()),
Loading history...
49
                $e->getCode(),
0 ignored issues
show
Bug introduced by
The method getCode() does not exist on Psr\Container\ContainerExceptionInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Psr\Container\NotFoundExceptionInterface or Interop\Container\Exception\ContainerException or Interop\Container\Exception\NotFoundException or Interop\Container\Exception\NotFoundException or Laminas\ServiceManager\E...tion\ExceptionInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
                $e->/** @scrutinizer ignore-call */ 
50
                    getCode(),
Loading history...
50
                $e
51
            );
52
        }
53
    }
54
}
55