Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PermissionDeniedException | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| superuserRequired | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| ownerRequired | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Domain\Exception; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use RuntimeException; |
| 12 | |
| 13 | /** |
| 14 | * Permission Denied Domain Exception. |
| 15 | * |
| 16 | * Thrown by PermissionGuard when the actor lacks the required access |
| 17 | * level for the requested operation on the given module. |
| 18 | * |
| 19 | * @package App\Core\Engine\Domain\Exception |
| 20 | */ |
| 21 | final class PermissionDeniedException extends RuntimeException |
| 22 | { |
| 23 | /** |
| 24 | * Creates a superuser-required exception for a module. |
| 25 | * |
| 26 | * @param string $moduleName The module that requires superuser access. |
| 27 | * @return self Configured exception instance. |
| 28 | */ |
| 29 | public static function superuserRequired(string $moduleName): self |
| 30 | { |
| 31 | return new self( |
| 32 | sprintf('Module "%s" requires superuser privileges.', $moduleName) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Creates an owner scope exception when actor does not own the record. |
| 38 | * |
| 39 | * @param string $moduleName The module where the access was denied. |
| 40 | * @param int $recordId The record ID that the actor does not own. |
| 41 | * @return self Configured exception instance. |
| 42 | */ |
| 43 | public static function ownerRequired(string $moduleName, int $recordId): self |
| 44 | { |
| 45 | return new self( |
| 46 | sprintf('Access denied to record #%d in module "%s": not the record owner.', $recordId, $moduleName) |
| 47 | ); |
| 48 | } |
| 49 | } |