ObjectManagerOptionFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 18
rs 9.8666
cc 2
nc 2
nop 3
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