ObjectManagerOptionFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 14
c 1
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Factory\Console\Option;
6
7
use Arp\LaminasDoctrine\Console\Option\ObjectManagerOption;
8
use Arp\LaminasFactory\AbstractFactory;
9
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
10
use Psr\Container\ContainerInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
13
final class ObjectManagerOptionFactory extends AbstractFactory
14
{
15
    /**
16
     * @var string|null
17
     */
18
    private ?string $defaultObjectManagerName = null;
19
20
    /**
21
     * @param ContainerInterface        $container
22
     * @param string                    $requestedName
23
     * @param array<string, mixed>|null $options
24
     *
25
     * @return ObjectManagerOption
26
     *
27
     * @throws ServiceNotCreatedException
28
     */
29
    public function __invoke(
30
        ContainerInterface $container,
31
        string $requestedName,
32
        array $options = null
33
    ): ObjectManagerOption {
34
        try {
35
            return new ObjectManagerOption(
36
                'object-manager',
37
                null,
38
                InputOption::VALUE_REQUIRED,
39
                'The object manager that should be used',
40
                $this->defaultObjectManagerName
41
            );
42
        } catch (\Exception $e) {
43
            throw new ServiceNotCreatedException(
44
                sprintf('Failed to create object manager options \'%s\': %s', $requestedName, $e->getMessage()),
45
                $e->getCode(),
46
                $e
47
            );
48
        }
49
    }
50
}
51