Passed
Pull Request — master (#5)
by Alex
09:53 queued 08:01
created

DateTimeZoneFactoryFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 16
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDateTime\Factory;
6
7
use Arp\DateTime\DateTimeZoneFactory;
8
use Arp\DateTime\Exception\DateTimeZoneFactoryException;
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 DateTimeZoneFactoryFactory extends AbstractFactory
15
{
16
    /**
17
     * @throws ContainerExceptionInterface
18
     */
19
    public function __invoke(
20
        ContainerInterface $container,
21
        string $requestedName,
22
        array $options = null
23
    ): DateTimeZoneFactory {
24
        $options = $options ?? $this->getServiceOptions($container, $requestedName, 'laminas_date_time');
25
26
        try {
27
            return new DateTimeZoneFactory(
28
                $options['class_name'] ?? \DateTimeZone::class,
29
            );
30
        } catch (DateTimeZoneFactoryException $e) {
31
            throw new ServiceNotCreatedException(
32
                sprintf('Failed to create date time zone factory \'%s\'', $requestedName),
33
                $e->getCode(),
34
                $e,
35
            );
36
        }
37
    }
38
}
39