Passed
Pull Request — master (#7)
by Alex
07:24
created

DateTimeFactoryFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 9
c 2
b 0
f 1
dl 0
loc 12
rs 9.9666
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\DateTime\Factory;
6
7
use Arp\DateTime\DateTimeFactory;
8
use Arp\DateTime\Exception\DateTimeFactoryException;
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
final class DateTimeFactoryFactory implements FactoryInterface
17
{
18
    /**
19
     * @param array $config
20
     *
21
     * @return DateTimeFactory
22
     *
23
     * @throws FactoryException If the factory cannot be created
24
     */
25
    public function create(array $config = []): DateTimeFactory
26
    {
27
        $dateTimeClassName = $config['date_class_name'] ?? null;
28
        $dateTimeZoneClassName = $config['time_zone_class_name'] ?? null;
29
30
        try {
31
            return new DateTimeFactory($dateTimeClassName, $dateTimeZoneClassName);
32
        } catch (DateTimeFactoryException $e) {
33
            throw new FactoryException(
34
                sprintf('Failed to create DateTimeFactory: %s', $e->getMessage()),
35
                $e->getCode(),
36
                $e
37
            );
38
        }
39
    }
40
}
41