aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/RangeFactory.php
diff options
context:
space:
mode:
authorRasmus Fuhse <fuhse@data-quest.de>2024-12-11 14:58:36 +0000
committerRasmus Fuhse <fuhse@data-quest.de>2024-12-11 14:58:36 +0000
commitc14cdd1a892fe19b9035feba01273ef5015cb64b (patch)
tree5c6e961de7e0b124e408957fa28aa633860aa511 /lib/classes/RangeFactory.php
parent44b518ce738a282fd0efa30e40e17f53b104e424 (diff)
Resolve "Wiki: Exception taucht auf, wenn ich mit autor-Berechtigungen eine nicht existierende Seite aufrufe"
Closes #4991 Merge request studip/studip!3750
Diffstat (limited to 'lib/classes/RangeFactory.php')
-rw-r--r--lib/classes/RangeFactory.php22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/classes/RangeFactory.php b/lib/classes/RangeFactory.php
index 8da592a..f70e25a 100644
--- a/lib/classes/RangeFactory.php
+++ b/lib/classes/RangeFactory.php
@@ -8,16 +8,24 @@
*/
final class RangeFactory
{
- const TYPE_MAPPING = [
+ public const TYPE_MAPPING = [
'sem' => 'course',
'user' => 'user',
'inst' => 'institute',
'fak' => 'institute',
];
- public static function find($id)
- {
- $type = get_object_type($id, ['sem', 'user', 'inst', 'fak']);
+ /**
+ * Finds a Range for a given id or false if there is no Range with the id.
+ * @param string $id Range id
+ * @param array $search_types array can have values of 'sem', 'user', 'inst' and/or 'fak'
+ * @return Range|false
+ */
+ public static function find(
+ string $id,
+ array $search_types = ['sem', 'user', 'inst', 'fak']
+ ) {
+ $type = get_object_type($id, $search_types);
if ($type === false) {
return false;
}
@@ -30,12 +38,10 @@ final class RangeFactory
*
* @param string $type Range type
* @param mixed $id Range id
- * @return mixed any of the supported range types
+ * @return Range any of the supported range types
* @throws Exception when an invalid range type was given
- *
- * @todo Should this be more dynamic in case any more ranges are added?
*/
- public static function createRange($type, $id)
+ public static function createRange(string $type, string $id): Range
{
if ($type === 'user') {
return new User($id);