Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| EmptyStructureAssignmentException | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| forNode | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| 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\Modules\Structure\Domain\Exception; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use DomainException; |
| 12 | |
| 13 | /** |
| 14 | * Exception thrown when assigning a record to a structure node that has no active users. |
| 15 | * |
| 16 | * Enforces Rule 1: It is strictly prohibited to assign records as owner or co-owner |
| 17 | * to an organizational unit that does not have at least one user assigned. |
| 18 | * |
| 19 | * @package App\Modules\Structure\Domain\Exception |
| 20 | */ |
| 21 | final class EmptyStructureAssignmentException extends DomainException |
| 22 | { |
| 23 | /** |
| 24 | * Factory method for empty structure node assignment attempt. |
| 25 | * |
| 26 | * @param int $structureId Structure node ID. |
| 27 | * @param string|null $structureName Structure node name if known. |
| 28 | * @return self |
| 29 | */ |
| 30 | public static function forNode(int $structureId, ?string $structureName = null): self |
| 31 | { |
| 32 | $label = $structureName !== null |
| 33 | ? sprintf('"%s" (ID: %d)', $structureName, $structureId) |
| 34 | : sprintf('ID %d', $structureId); |
| 35 | |
| 36 | return new self( |
| 37 | sprintf( |
| 38 | 'Cannot assign ownership to structure node %s because it has no assigned users. ' |
| 39 | . 'Assign at least one user to this organizational unit first.', |
| 40 | $label |
| 41 | ) |
| 42 | ); |
| 43 | } |
| 44 | } |