From 7245d15abe045983588c7d812e79b2ba2020b458 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 5 Oct 2021 19:57:26 +0100 Subject: [PATCH] PermissionParser: Throw more specific exceptions --- src/permission/PermissionParser.php | 7 +++-- src/permission/PermissionParserException.php | 31 ++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/permission/PermissionParserException.php diff --git a/src/permission/PermissionParser.php b/src/permission/PermissionParser.php index 7115a5536f..c7733a49cd 100644 --- a/src/permission/PermissionParser.php +++ b/src/permission/PermissionParser.php @@ -55,7 +55,7 @@ class PermissionParser{ /** * @param bool|string $value * - * @throws \InvalidArgumentException + * @throws PermissionParserException */ public static function defaultFromString($value) : string{ if(is_bool($value)){ @@ -70,7 +70,7 @@ class PermissionParser{ return self::DEFAULT_STRING_MAP[$lower]; } - throw new \InvalidArgumentException("Unknown permission default name \"$value\""); + throw new PermissionParserException("Unknown permission default name \"$value\""); } /** @@ -79,6 +79,7 @@ class PermissionParser{ * * @return Permission[][] * @phpstan-return array> + * @throws PermissionParserException */ public static function loadPermissions(array $data, string $default = self::DEFAULT_FALSE) : array{ $result = []; @@ -89,7 +90,7 @@ class PermissionParser{ } if(isset($entry["children"])){ - throw new \InvalidArgumentException("Nested permission declarations are no longer supported. Declare each permission separately."); + throw new PermissionParserException("Nested permission declarations are no longer supported. Declare each permission separately."); } if(isset($entry["description"])){ diff --git a/src/permission/PermissionParserException.php b/src/permission/PermissionParserException.php new file mode 100644 index 0000000000..a0231f8058 --- /dev/null +++ b/src/permission/PermissionParserException.php @@ -0,0 +1,31 @@ +