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

ClockFactory::__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\Psr;
6
7
use Arp\DateTime\Psr\Clock;
8
use Arp\LaminasFactory\AbstractFactory;
9
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
10
use Psr\Container\ContainerExceptionInterface;
11
use Psr\Container\ContainerInterface;
12
13
final class ClockFactory extends AbstractFactory
14
{
15
    /**
16
     * @throws ContainerExceptionInterface
17
     */
18
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): Clock
19
    {
20
        $options = $options ?? $this->getServiceOptions($container, $requestedName, 'laminas_date_time');
21
22
        if (empty($options['factory'])) {
23
            throw new ServiceNotCreatedException(
24
                sprintf(
25
                    'The required \'factory\' configuration option is missing for service \'%s\'',
26
                    $requestedName
27
                ),
28
            );
29
        }
30
31
        return new Clock(
32
            $this->getService($container, $options['factory'], $requestedName),
33
            $options['date_time_zone'] ?? null
34
        );
35
    }
36
}
37