DateTimeFactoryFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactory;
8
use Arp\DateTime\Exception\DateTimeFactoryException;
9
use Arp\LaminasFactory\AbstractFactory;
10
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
11
use Psr\Container\ContainerExceptionInterface;
12
use Psr\Container\ContainerInterface;
13
14
final class DateTimeFactoryFactory extends AbstractFactory
15
{
16
    /**
17
     * @throws ServiceNotCreatedException
18
     * @throws ContainerExceptionInterface
19
     */
20
    public function __invoke(
21
        ContainerInterface $container,
22
        string $requestedName,
23
        array $options = null
24
    ): DateTimeFactory {
25
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
26
27
        try {
28
            return new DateTimeFactory(
29
                $options['date_time_zone_factory'] ?? null,
30
                $options['date_time_class_name'] ?? null
31
            );
32
        } catch (DateTimeFactoryException $e) {
33
            throw new ServiceNotCreatedException(
34
                sprintf('Failed to create date time factory: %s', $e->getMessage()),
35
                $e->getCode(),
36
                $e
37
            );
38
        }
39
    }
40
}
41