alex-patterson-webdev /
date-time
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Arp\DateTime; |
||||
| 6 | |||||
| 7 | use Arp\DateTime\Exception\DateIntervalFactoryException; |
||||
| 8 | use Arp\DateTime\Exception\DateTimeFactoryException; |
||||
| 9 | use Arp\DateTime\Exception\DateTimeZoneFactoryException; |
||||
| 10 | |||||
| 11 | final class DateFactory implements DateFactoryInterface |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @throws DateTimeFactoryException |
||||
| 15 | */ |
||||
| 16 | public function __construct( |
||||
| 17 | private ?DateTimeFactoryInterface $dateTimeFactory = null, |
||||
| 18 | private ?DateTimeZoneFactoryInterface $dateTimeZoneFactory = null, |
||||
| 19 | private ?DateIntervalFactoryInterface $dateIntervalFactory = null |
||||
| 20 | ) { |
||||
| 21 | $this->dateTimeZoneFactory = $dateTimeZoneFactory ?? new DateTimeZoneFactory(); |
||||
| 22 | $this->dateTimeFactory = $dateTimeFactory ?? new DateTimeFactory($this->dateTimeZoneFactory); |
||||
| 23 | $this->dateIntervalFactory = $dateIntervalFactory ?? new DateIntervalFactory(); |
||||
| 24 | } |
||||
| 25 | |||||
| 26 | /** |
||||
| 27 | * @throws DateTimeFactoryException |
||||
| 28 | */ |
||||
| 29 | public function createDateTime( |
||||
| 30 | ?string $spec = null, |
||||
| 31 | string|\DateTimeZone|null $timeZone = null |
||||
| 32 | ): \DateTimeInterface { |
||||
| 33 | return $this->dateTimeFactory->createDateTime($spec, $timeZone); |
||||
|
0 ignored issues
–
show
|
|||||
| 34 | } |
||||
| 35 | |||||
| 36 | /** |
||||
| 37 | * @throws DateTimeFactoryException |
||||
| 38 | */ |
||||
| 39 | public function createFromFormat( |
||||
| 40 | string $format, |
||||
| 41 | string $spec, |
||||
| 42 | string|\DateTimeZone|null $timeZone = null |
||||
| 43 | ): \DateTimeInterface { |
||||
| 44 | return $this->dateTimeFactory->createFromFormat($format, $spec, $timeZone); |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | /** |
||||
| 48 | * @throws DateTimeZoneFactoryException |
||||
| 49 | */ |
||||
| 50 | public function createDateTimeZone(string $spec): \DateTimeZone |
||||
| 51 | { |
||||
| 52 | return $this->dateTimeZoneFactory->createDateTimeZone($spec); |
||||
|
0 ignored issues
–
show
The method
createDateTimeZone() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 53 | } |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * @throws DateIntervalFactoryException |
||||
| 57 | */ |
||||
| 58 | public function createDateInterval(string $spec): \DateInterval |
||||
| 59 | { |
||||
| 60 | return $this->dateIntervalFactory->createDateInterval($spec); |
||||
|
0 ignored issues
–
show
The method
createDateInterval() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 61 | } |
||||
| 62 | } |
||||
| 63 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.