Passed
Pull Request — master (#7)
by Alex
12:47
created

CurrentDateTimeProviderFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\DateTime\Factory;
6
7
use Arp\DateTime\CurrentDateTimeProvider;
8
use Arp\DateTime\DateTimeFactoryInterface;
9
use Arp\Factory\Exception\FactoryException;
10
use Arp\Factory\FactoryInterface;
11
12
/**
13
 * @author  Alex Patterson <[email protected]>
14
 * @package Arp\DateTime\Factory
15
 */
16
class CurrentDateTimeProviderFactory implements FactoryInterface
17
{
18
    /**
19
     * @var FactoryInterface
20
     */
21
    private FactoryInterface $dateTimeFactoryFactory;
22
23
    /**
24
     * @param FactoryInterface|null $dateTimeFactoryFactory
25
     */
26
    public function __construct(FactoryInterface $dateTimeFactoryFactory = null)
27
    {
28
        $this->dateTimeFactoryFactory = $dateTimeFactoryFactory ?? new DateTimeFactoryFactory();
29
    }
30
31
    /**
32
     * @param array $config
33
     *
34
     * @return CurrentDateTimeProvider
35
     *
36
     * @throws FactoryException If the date time provider cannot be created.
37
     */
38
    public function create(array $config = []): CurrentDateTimeProvider
39
    {
40
        /** @var DateTimeFactoryInterface|array $dateTimeFactory */
41
        $dateTimeFactory = $config['date_time_factory'] ?? [];
42
        if (is_array($dateTimeFactory)) {
0 ignored issues
show
introduced by
The condition is_array($dateTimeFactory) is always true.
Loading history...
43
            $dateTimeFactory = $this->dateTimeFactoryFactory->create($dateTimeFactory);
44
        }
45
46
        return new CurrentDateTimeProvider($dateTimeFactory);
47
    }
48
}
49