99
1010use function count ;
1111
12+ /**
13+ * @template TPoint of DateTimeInterface
14+ * @implements IntervalInterface<TPoint>
15+ */
1216final class DateTimeInterval implements IntervalInterface
1317{
1418 /**
15- * @var DateTimeInterface
19+ * @var TPoint
1620 */
1721 private $ low ;
1822
1923 /**
20- * @var DateTimeInterface
24+ * @var TPoint
2125 */
2226 private $ high ;
2327
2428 /**
2529 * DateTimeInterval constructor
26- * @param DateTimeInterface $low
27- * @param DateTimeInterface $high
30+ * @param TPoint $low
31+ * @param TPoint $high
2832 */
2933 public function __construct ($ low , $ high )
3034 {
@@ -37,10 +41,12 @@ public function __construct($low, $high)
3741 }
3842
3943 /**
40- * @param DateTimeInterface[] $interval
41- * @return DateTimeInterval
44+ * @phpstan-ignore-next-line
45+ * @psalm-template TPoint of DateTimeInterface
46+ * @param TPoint[] $interval
47+ * @return IntervalInterface<TPoint>
4248 */
43- public static function fromArray ($ interval ): DateTimeInterval
49+ public static function fromArray (array $ interval ): IntervalInterface
4450 {
4551 if (count ($ interval ) !== 2 ) {
4652 throw new InvalidArgumentException ('Wrong interval array ' );
@@ -59,20 +65,20 @@ public function getHigh(): DateTimeInterface
5965 }
6066
6167 /**
62- * @param DateTimeInterval $otherInterval
68+ * @param IntervalInterface<TPoint> $otherInterval
6369 * @return bool
6470 */
65- public function equalTo ($ otherInterval ): bool
71+ public function equalTo (IntervalInterface $ otherInterval ): bool
6672 {
6773 return $ this ->getLow ()->getTimestamp () === $ otherInterval ->getLow ()->getTimestamp () &&
6874 $ this ->getHigh ()->getTimestamp () === $ otherInterval ->getHigh ()->getTimestamp ();
6975 }
7076
7177 /**
72- * @param DateTimeInterval $otherInterval
78+ * @param IntervalInterface<TPoint> $otherInterval
7379 * @return bool
7480 */
75- public function lessThan ($ otherInterval ): bool
81+ public function lessThan (IntervalInterface $ otherInterval ): bool
7682 {
7783 return $ this ->getLow ()->getTimestamp () < $ otherInterval ->getLow ()->getTimestamp () ||
7884 (
@@ -82,19 +88,19 @@ public function lessThan($otherInterval): bool
8288 }
8389
8490 /**
85- * @param DateTimeInterval $otherInterval
91+ * @param IntervalInterface<TPoint> $otherInterval
8692 * @return bool
8793 */
88- public function intersect ($ otherInterval ): bool
94+ public function intersect (IntervalInterface $ otherInterval ): bool
8995 {
9096 return !($ this ->getHigh () < $ otherInterval ->getLow () || $ otherInterval ->getHigh () < $ this ->getLow ());
9197 }
9298
9399 /**
94- * @param DateTimeInterval $otherInterval
95- * @return DateTimeInterval
100+ * @param IntervalInterface<TPoint> $otherInterval
101+ * @return IntervalInterface<TPoint>
96102 */
97- public function merge ($ otherInterval ): DateTimeInterval
103+ public function merge (IntervalInterface $ otherInterval ): IntervalInterface
98104 {
99105 return new DateTimeInterval (
100106 min ($ this ->getLow (), $ otherInterval ->getLow ()),
0 commit comments