@@ -48,61 +48,97 @@ protected static function isDisjoint(?int $minA, ?int $maxA, ?int $minB, ?int $m
4848 }
4949
5050 /**
51- * Return the range of integers smaller than (or equal to) the given value
51+ * Return the range of integers smaller than the given value
5252 *
5353 * @param int|float $value
54- * @param bool $orEqual
5554 * @return Type
5655 */
57- public static function createAllSmallerThan ($ value, bool $ orEqual = false ): Type
56+ public static function createAllSmallerThan ($ value ): Type
5857 {
5958 if (is_int ($ value )) {
60- return self ::fromInterval (null , $ value , $ orEqual ? 0 : -1 );
59+ return self ::fromInterval (null , $ value , -1 );
6160 }
6261
63- if ($ value > PHP_INT_MAX || $ value >= PHP_INT_MAX && $ orEqual ) {
62+ if ($ value > PHP_INT_MAX ) {
6463 return new IntegerType ();
6564 }
6665
67- if ($ value < PHP_INT_MIN || $ value < = PHP_INT_MIN && ! $ orEqual ) {
66+ if ($ value <= PHP_INT_MIN ) {
6867 return new NeverType ();
6968 }
7069
71- if ($ orEqual ) {
72- return self ::fromInterval (null , (int ) floor ($ value ));
73- }
74-
7570 return self ::fromInterval (null , (int ) ceil ($ value ), -1 );
7671 }
7772
7873 /**
79- * Return the range of integers greater than ( or equal to) the given value
74+ * Return the range of integers smaller than or equal to the given value
8075 *
8176 * @param int|float $value
82- * @param bool $orEqual
8377 * @return Type
8478 */
85- public static function createAllGreaterThan ($ value, bool $ orEqual = false ): Type
79+ public static function createAllSmallerThanOrEqualTo ($ value ): Type
8680 {
8781 if (is_int ($ value )) {
88- return self ::fromInterval ($ value , null , $ orEqual ? 0 : 1 );
82+ return self ::fromInterval (null , $ value );
8983 }
9084
91- if ($ value < PHP_INT_MIN || $ value <= PHP_INT_MIN && $ orEqual ) {
85+ if ($ value >= PHP_INT_MAX ) {
9286 return new IntegerType ();
9387 }
9488
95- if ($ value > PHP_INT_MAX || $ value >= PHP_INT_MAX && ! $ orEqual ) {
89+ if ($ value < PHP_INT_MIN ) {
9690 return new NeverType ();
9791 }
9892
99- if ($ orEqual ) {
100- return self ::fromInterval ((int ) ceil ($ value ), null );
93+ return self ::fromInterval (null , (int ) floor ($ value ));
94+ }
95+
96+ /**
97+ * Return the range of integers greater than the given value
98+ *
99+ * @param int|float $value
100+ * @return Type
101+ */
102+ public static function createAllGreaterThan ($ value ): Type
103+ {
104+ if (is_int ($ value )) {
105+ return self ::fromInterval ($ value , null , 1 );
106+ }
107+
108+ if ($ value < PHP_INT_MIN ) {
109+ return new IntegerType ();
110+ }
111+
112+ if ($ value >= PHP_INT_MAX ) {
113+ return new NeverType ();
101114 }
102115
103116 return self ::fromInterval ((int ) floor ($ value ), null , 1 );
104117 }
105118
119+ /**
120+ * Return the range of integers greater than or equal to the given value
121+ *
122+ * @param int|float $value
123+ * @return Type
124+ */
125+ public static function createAllGreaterThanOrEqualTo ($ value ): Type
126+ {
127+ if (is_int ($ value )) {
128+ return self ::fromInterval ($ value , null );
129+ }
130+
131+ if ($ value <= PHP_INT_MIN ) {
132+ return new IntegerType ();
133+ }
134+
135+ if ($ value > PHP_INT_MAX ) {
136+ return new NeverType ();
137+ }
138+
139+ return self ::fromInterval ((int ) ceil ($ value ), null );
140+ }
141+
106142 public function getMin (): ?int
107143 {
108144 return $ this ->min ;
@@ -269,40 +305,61 @@ public function isGreaterThan(Type $otherType, bool $orEqual = false): TrinaryLo
269305 return TrinaryLogic::extremeIdentity ($ minIsSmaller , $ maxIsSmaller );
270306 }
271307
272- public function getSmallerType (bool $ orEqual = false ): Type
308+ public function getSmallerType (): Type
309+ {
310+ $ subtractedTypes = [
311+ new ConstantBooleanType (true ),
312+ ];
313+
314+ if ($ this ->max !== null ) {
315+ $ subtractedTypes [] = self ::createAllGreaterThanOrEqualTo ($ this ->max );
316+ }
317+
318+ return TypeCombinator::remove (new MixedType (), TypeCombinator::union (...$ subtractedTypes ));
319+ }
320+
321+ public function getSmallerOrEqualType (): Type
273322 {
274323 $ subtractedTypes = [];
275324
276325 if ($ this ->max !== null ) {
277- $ subtractedTypes [] = self ::createAllGreaterThan ($ this ->max , ! $ orEqual );
326+ $ subtractedTypes [] = self ::createAllGreaterThan ($ this ->max );
278327 }
279328
280- if (!$ orEqual ) {
329+ return TypeCombinator::remove (new MixedType (), TypeCombinator::union (...$ subtractedTypes ));
330+ }
331+
332+ public function getGreaterType (): Type
333+ {
334+ $ subtractedTypes = [
335+ new NullType (),
336+ new ConstantBooleanType (false ),
337+ ];
338+
339+ if ($ this ->min !== null ) {
340+ $ subtractedTypes [] = self ::createAllSmallerThanOrEqualTo ($ this ->min );
341+ }
342+
343+ if ($ this ->min !== null && $ this ->min > 0 || $ this ->max !== null && $ this ->max < 0 ) {
281344 $ subtractedTypes [] = new ConstantBooleanType (true );
282345 }
283346
284347 return TypeCombinator::remove (new MixedType (), TypeCombinator::union (...$ subtractedTypes ));
285348 }
286349
287- public function getGreaterType ( bool $ orEqual = false ): Type
350+ public function getGreaterOrEqualType ( ): Type
288351 {
289352 $ subtractedTypes = [];
290353
291354 if ($ this ->min !== null ) {
292- $ subtractedTypes [] = self ::createAllSmallerThan ($ this ->min , ! $ orEqual );
355+ $ subtractedTypes [] = self ::createAllSmallerThan ($ this ->min );
293356 }
294357
295- $ alwaysTruthy = $ this ->min !== null && $ this ->min > 0 || $ this ->max !== null && $ this ->max < 0 ;
296-
297- if ($ alwaysTruthy || !$ orEqual ) {
358+ if ($ this ->min !== null && $ this ->min > 0 || $ this ->max !== null && $ this ->max < 0 ) {
298359 $ subtractedTypes [] = new NullType ();
299360 $ subtractedTypes [] = new ConstantBooleanType (false );
300361 }
301362
302- if ($ alwaysTruthy && !$ orEqual ) {
303- $ subtractedTypes [] = new ConstantBooleanType (true );
304- }
305-
306363 return TypeCombinator::remove (new MixedType (), TypeCombinator::union (...$ subtractedTypes ));
307364 }
308365
0 commit comments