Lines
85.71%
6 / 7
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AgentStatProcessor | 85.71% | 6 / 7 | 50.00% | 1 / 2 | 3.03 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| process | 83.33% | 5 / 6 | 0.00% | 0 / 1 | 2.02 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\State; | |
| 6 | ||
| 7 | use ApiPlatform\Metadata\Operation; | |
| 8 | use ApiPlatform\State\ProcessorInterface; | |
| 9 | use App\Dto\AgentStatInput; | |
| 10 | use App\Entity\AgentStat; | |
| 11 | use App\Entity\User; | |
| 12 | use App\Notifier\ChatActivity; | |
| 13 | use App\Service\AgentStatService; | |
| 14 | use Symfony\Bundle\SecurityBundle\Security; | |
| 15 | ||
| 16 | /** | |
| 17 | * POST /api/agent-stats: saves the validated input for the current user and posts it to Slack and Telegram. | |
| 18 | * A StatsAlreadyAddedException is a 409, an AgentNameException a 422 (see AgentStat's #[ApiResource]). | |
| 19 | * | |
| 20 | * @implements ProcessorInterface<AgentStatInput, AgentStat> | |
| 21 | */ | |
| 22 | final readonly class AgentStatProcessor implements ProcessorInterface | |
| 23 | { | |
| 24 | public function __construct( | |
| 25 | private AgentStatService $agentStatService, | |
| 26 | private Security $security, | |
| 27 | private ChatActivity $chatActivity, | |
| 28 | ) { | |
| 29 | } | |
| 30 | ||
| 31 | public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): AgentStat | |
| 32 | { | |
| 33 | $user = $this->security->getUser(); | |
| 34 | if (!$user instanceof User) { | |
| 35 | throw new \LogicException('The operation requires ROLE_USER.'); | |
| 36 | } | |
| 37 | ||
| 38 | $agentStat = $this->agentStatService->create($user, $data); | |
| 39 | $this->chatActivity->statsUploaded($agentStat); | |
| 40 | ||
| 41 | return $agentStat; | |
| 42 | } | |
| 43 | } |