Passed
Pull Request — master (#2)
by Alex
08:14
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
 * @deprecated
14
 * Factory class for the Doctrine Configuration via the Laminas ServiceManager. This is not ideal as we treat the
15
 * manager as a ServiceLocator, however this class is already an abstraction that is used as an implementation detail
16
 * of ConfigurationManager.
17
 *
18
 * @author  Alex Patterson <[email protected]>
19
 * @package Arp\LaminasDoctrine\Service\Configuration
20
 */
21
final class ConfigurationFactory implements ConfigurationFactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Arp\LaminasDoctrine\Serv...urationFactoryInterface has been deprecated. ( Ignorable by Annotation )

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

21
final class ConfigurationFactory implements /** @scrutinizer ignore-deprecated */ ConfigurationFactoryInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
22
{
23
    /**
24
     * @var ServiceLocatorInterface
25
     */
26
    private ServiceLocatorInterface $serviceManager;
27
28
    /**
29
     * @param ServiceLocatorInterface $serviceManager
30
     */
31
    public function __construct(ServiceLocatorInterface $serviceManager)
32
    {
33
        $this->serviceManager = $serviceManager;
34
    }
35
36
    /**
37
     * @param array<string, mixed> $config
38
     *
39
     * @return Configuration
40
     *
41
     * @throws ConfigurationFactoryException
42
     */
43
    public function create(array $config): Configuration
44
    {
45
        try {
46
            return $this->serviceManager->build(Configuration::class, $config);
47
        } catch (ContainerExceptionInterface $e) {
48
            throw new ConfigurationFactoryException(
0 ignored issues
show
Deprecated Code introduced by
The class Arp\LaminasDoctrine\Serv...urationFactoryException has been deprecated. ( Ignorable by Annotation )

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

48
            throw /** @scrutinizer ignore-deprecated */ new ConfigurationFactoryException(
Loading history...
49
                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

49
                sprintf('Failed to create ORM Configuration: %s', $e->/** @scrutinizer ignore-call */ getMessage()),
Loading history...
50
                $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

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