aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2025-12-17 11:52:54 +0100
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2025-12-17 11:52:54 +0100
commit2f6970f4628934eb7bf8c56332a7aa25e1141ea9 (patch)
treebdacf90e0be9724ca08c1624592031eac1ade1dd
parent166eb5d657e9bccfbcd0f891d78a000b7b0fcb3f (diff)
improve signature and disallow calling RangeConfig::get() without any parameters, fixes #6065
Closes #6065 Merge request studip/studip!4619
-rw-r--r--lib/classes/RangeConfig.php22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/classes/RangeConfig.php b/lib/classes/RangeConfig.php
index ad48207..2e90c86 100644
--- a/lib/classes/RangeConfig.php
+++ b/lib/classes/RangeConfig.php
@@ -37,25 +37,23 @@ class RangeConfig extends Config
/**
* returns cached instance for given range_id
* creates new objects if needed
- * @param string $range_id
- * @return RangeConfig
+ *
+ * @param string|Range|null $range_id Range id or object (never null, we
+ * need this just for compatibility with
+ * Config::get())
*/
- public static function get()
+ public static function get(string|Range|null $range_id = null): static
{
- if (func_num_args() === 0 || func_get_arg(0) === null) {
- return new static(true);
+ if ($range_id === null) {
+ throw new InvalidArgumentException('No range_id given');
}
- $range_id = func_get_arg(0);
-
if ($range_id instanceof Range) {
$range_id = $range_id->getRangeId();
}
- if (!isset(static::$instances[$range_id])) {
- static::$instances[$range_id] = new static($range_id);
- }
- return static::$instances[$range_id];
+ return static::$instances[$range_id]
+ ??= new static($range_id);
}
/**
@@ -67,7 +65,7 @@ class RangeConfig extends Config
*/
public static function set()
{
- list($range_id, $my_instance) = func_get_args();
+ [$range_id, $my_instance] = func_get_args();
self::$instances[$range_id] = $my_instance;
}