Lines
100.00%
6 / 6
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkerRegistryEditor | 100.00% | 6 / 6 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| forApp | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| updateEntity | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker; | |
| 6 | ||
| 7 | use Stewart\Contracts\App\AppId; | |
| 8 | use Stewart\Contracts\Entity\EntityId; | |
| 9 | use Stewart\Contracts\Exception\RegistryEditException; | |
| 10 | use Stewart\Contracts\Registry\RegisteredEntity; | |
| 11 | use Stewart\Contracts\Registry\RegistryEditor; | |
| 12 | use Stewart\Contracts\Registry\Update\EntityRegistryUpdate; | |
| 13 | use Stewart\Runtime\Model\ResourceScope; | |
| 14 | use Stewart\Runtime\Worker\Registry\RegistryEditRequester; | |
| 15 | ||
| 16 | final readonly class WorkerRegistryEditor implements RegistryEditor | |
| 17 | { | |
| 18 | public function __construct( | |
| 19 | private RegistryEditRequester $requester, | |
| 20 | private ResourceScope $resourceScope, | |
| 21 | ) {} | |
| 22 | ||
| 23 | public function forApp(AppId $appId): self | |
| 24 | { | |
| 25 | return new self($this->requester, ResourceScope::forApp($appId)); | |
| 26 | } | |
| 27 | ||
| 28 | public function updateEntity(EntityId|string $entityId, EntityRegistryUpdate $update): RegisteredEntity | |
| 29 | { | |
| 30 | $entityId = EntityId::fromStringOrId($entityId); | |
| 31 | ||
| 32 | if ($update->isEmpty()) { | |
| 33 | throw RegistryEditException::nothingToUpdate($entityId); | |
| 34 | } | |
| 35 | ||
| 36 | return $this->requester->requestEntityUpdate($this->resourceScope, $entityId, $update); | |
| 37 | } | |
| 38 | } |