PermissionParser: Throw more specific exceptions

This commit is contained in:
Dylan K. Taylor 2021-10-05 19:57:26 +01:00
parent 13178a47a5
commit 7245d15abe
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 35 additions and 3 deletions

View File

@ -55,7 +55,7 @@ class PermissionParser{
/** /**
* @param bool|string $value * @param bool|string $value
* *
* @throws \InvalidArgumentException * @throws PermissionParserException
*/ */
public static function defaultFromString($value) : string{ public static function defaultFromString($value) : string{
if(is_bool($value)){ if(is_bool($value)){
@ -70,7 +70,7 @@ class PermissionParser{
return self::DEFAULT_STRING_MAP[$lower]; 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[][] * @return Permission[][]
* @phpstan-return array<string, list<Permission>> * @phpstan-return array<string, list<Permission>>
* @throws PermissionParserException
*/ */
public static function loadPermissions(array $data, string $default = self::DEFAULT_FALSE) : array{ public static function loadPermissions(array $data, string $default = self::DEFAULT_FALSE) : array{
$result = []; $result = [];
@ -89,7 +90,7 @@ class PermissionParser{
} }
if(isset($entry["children"])){ 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"])){ if(isset($entry["description"])){

View File

@ -0,0 +1,31 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\permission;
/**
* Thrown by PermissionParser when it encounters data that it doesn't like.
*/
final class PermissionParserException extends \RuntimeException{
}