Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 43... Zeile 43...
43
	}
43
	}
Zeile 44... Zeile 44...
44
 
44
 
45
 
45
 
46
	/**
-
 
47
	 * Converts false to null, does not change other values.
-
 
48
	 * @param  mixed  $value
46
	/**
49
	 * @return mixed
47
	 * Converts false to null, does not change other values.
50
	 */
48
	 */
51
	public static function falseToNull($value)
49
	public static function falseToNull(mixed $value): mixed
52
	{
50
	{
Zeile 53... Zeile 51...
53
		return $value === false ? null : $value;
51
		return $value === false ? null : $value;
54
	}
52
	}
55
 
-
 
56
 
-
 
57
	/**
-
 
58
	 * Returns value clamped to the inclusive range of min and max.
-
 
59
	 * @param  int|float  $value
53
 
60
	 * @param  int|float  $min
54
 
61
	 * @param  int|float  $max
55
	/**
62
	 * @return int|float
56
	 * Returns value clamped to the inclusive range of min and max.
63
	 */
57
	 */
64
	public static function clamp($value, $min, $max)
58
	public static function clamp(int|float $value, int|float $min, int|float $max): int|float
Zeile 86... Zeile 80...
86
			}
80
			}
87
		}
81
		}
Zeile 88... Zeile 82...
88
 
82
 
89
		return $best;
83
		return $best;
-
 
84
	}
-
 
85
 
-
 
86
 
-
 
87
	/**
-
 
88
	 * Compares two values in the same way that PHP does. Recognizes operators: >, >=, <, <=, =, ==, ===, !=, !==, <>
-
 
89
	 */
-
 
90
	public static function compare(mixed $left, string $operator, mixed $right): bool
-
 
91
	{
-
 
92
		return match ($operator) {
-
 
93
			'>' => $left > $right,
-
 
94
			'>=' => $left >= $right,
-
 
95
			'<' => $left < $right,
-
 
96
			'<=' => $left <= $right,
-
 
97
			'=', '==' => $left == $right,
-
 
98
			'===' => $left === $right,
-
 
99
			'!=', '<>' => $left != $right,
-
 
100
			'!==' => $left !== $right,
-
 
101
			default => throw new Nette\InvalidArgumentException("Unknown operator '$operator'"),
-
 
102
		};
90
	}
103
	}