DateTimeFactoryFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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