| Total Complexity | 4 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Coverage | 95% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | final readonly class RefreshSameCommand implements CommandInterface |
||
|
|
|||
| 15 | { |
||
| 16 | public function __construct( |
||
| 17 | private QueryRepositoryInterface $repository, |
||
| 18 | 13 | private MatchQueryInterface $matchQuery |
|
| 19 | ){ |
||
| 20 | 13 | } |
|
| 21 | 13 | ||
| 22 | /** |
||
| 23 | 8 | * @return void |
|
| 24 | */ |
||
| 25 | 8 | #[\Override] |
|
| 26 | 8 | public function command(MethodInvocation $invocation, ResourceObject $ro) |
|
| 27 | { |
||
| 28 | unset($invocation); |
||
| 29 | 8 | $getQuery = $this->getQuery($ro); |
|
| 30 | 8 | $delUri = clone $ro->uri; |
|
| 31 | 7 | $delUri->query = $getQuery; |
|
| 32 | 7 | ||
| 33 | // delete data in repository |
||
| 34 | $this->repository->purge($delUri); |
||
| 35 | 7 | ||
| 36 | // GET for re-generate (in interceptor) |
||
| 37 | $ro->uri->query = $getQuery; |
||
| 38 | 7 | $get = [$ro, 'onGet']; |
|
| 39 | 7 | if (is_callable($get)) { |
|
| 40 | 7 | call_user_func_array($get, array_values($getQuery)); |
|
| 41 | } |
||
| 42 | 7 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * @return array<string, mixed> |
||
| 46 | * |
||
| 47 | 8 | * @throws ReflectionException |
|
| 48 | */ |
||
| 49 | 8 | private function getQuery(ResourceObject $ro): array |
|
| 50 | 8 | { |
|
| 51 | 8 | return $this->matchQuery->__invoke($ro); |
|
| 52 | 8 | } |
|
| 54 |