DateIntervalFactory::createDateInterval()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 7
c 1
b 1
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\DateTime;
6
7
use Arp\DateTime\Exception\DateIntervalFactoryException;
8
9
final class DateIntervalFactory implements DateIntervalFactoryInterface
10
{
11
    /**
12
     * @throws DateIntervalFactoryException
13
     */
14
    public function createDateInterval(string $spec): \DateInterval
15
    {
16
        try {
17
            return new \DateInterval($spec);
18
        } catch (\Exception $e) {
19
            throw new DateIntervalFactoryException(
20
                sprintf('Failed to create a valid \DateInterval instance using \'%s\'', $spec),
21
                $e->getCode(),
22
                $e,
23
            );
24
        }
25
    }
26
}
27