• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / docker-symfony-api / #74

pending completion
#74

push

DKravtsov
Php 8.2, symfony 6.2, updated RabbitMQ, updated composer dependencies, refactoring.

51 of 51 new or added lines in 44 files covered. (100.0%)

1479 of 2668 relevant lines covered (55.43%)

23.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/General/Transport/ValueResolver/RestDtoValueResolver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\General\Transport\ValueResolver;
6

7
use App\General\Application\DTO\Interfaces\RestDtoInterface;
8
use App\General\Transport\Rest\Controller;
9
use App\General\Transport\Rest\ControllerCollection;
10
use AutoMapperPlus\AutoMapperInterface;
11
use Generator;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
14
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
15
use Throwable;
16

17
use function count;
18
use function explode;
19
use function in_array;
20

21
/**
22
 * Class RestDtoValueResolver
23
 *
24
 * @package App\General
25
 */
26
class RestDtoValueResolver implements ValueResolverInterface
27
{
28
    private const CONTROLLER_KEY = '_controller';
29

30
    /**
31
     * @var array<int, string>
32
     */
33
    private array $supportedActions = [
34
        Controller::ACTION_CREATE,
35
        Controller::ACTION_UPDATE,
36
        Controller::ACTION_PATCH,
37
    ];
38

39
    /**
40
     * @var array<string, string>
41
     */
42
    private array $actionMethodMap = [
43
        Controller::ACTION_CREATE => Controller::METHOD_CREATE,
44
        Controller::ACTION_UPDATE => Controller::METHOD_UPDATE,
45
        Controller::ACTION_PATCH => Controller::METHOD_PATCH,
46
    ];
47

48
    private ?string $controllerName = null;
49
    private ?string $actionName = null;
50

51
    /**
52
     * Constructor
53
     *
54
     * @param ControllerCollection<Controller> $controllerCollection
55
     */
56
    public function __construct(
57
        private readonly ControllerCollection $controllerCollection,
58
        private readonly AutoMapperInterface $autoMapper,
59
    ) {
60
    }
32✔
61

62
    public function supports(Request $request, ArgumentMetadata $argument): bool
63
    {
64
        $bits = explode('::', (string)$request->attributes->get(self::CONTROLLER_KEY, ''));
32✔
65

66
        if (count($bits) !== 2) {
32✔
67
            return false;
2✔
68
        }
69

70
        [$controllerName, $actionName] = $bits;
30✔
71

72
        $output = $argument->getType() === RestDtoInterface::class
30✔
73
            && in_array($actionName, $this->supportedActions, true)
30✔
74
            && $this->controllerCollection->has($controllerName);
30✔
75

76
        if ($output === true) {
30✔
77
            $this->controllerName = $controllerName;
30✔
78
            $this->actionName = $actionName;
30✔
79
        }
80

81
        return $output;
30✔
82
    }
83

84
    /**
85
     * {@inheritdoc}
86
     *
87
     * @return Generator<RestDtoInterface>
88
     *
89
     * @throws Throwable
90
     */
91
    public function resolve(Request $request, ArgumentMetadata $argument): Generator
92
    {
93
        if (!$this->supports($request, $argument)) {
32✔
94
            return [];
2✔
95
        }
96

97
        if ($this->controllerName === null) {
30✔
98
            return [];
×
99
        }
100

101
        $dtoClass = $this->controllerCollection
30✔
102
            ->get($this->controllerName)
30✔
103
            ->getDtoClass($this->actionMethodMap[$this->actionName] ?? null);
30✔
104

105
        yield $this->autoMapper->map($request, $dtoClass);
30✔
106
    }
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc