• 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

0.0
/src/User/Transport/Form/DataTransformer/UserGroupTransformer.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\User\Transport\Form\DataTransformer;
6

7
use App\User\Application\Resource\UserGroupResource;
8
use App\User\Domain\Entity\UserGroup;
9
use Stringable;
10
use Symfony\Component\Form\DataTransformerInterface;
11
use Symfony\Component\Form\Exception\TransformationFailedException;
12
use Throwable;
13

14
use function array_map;
15
use function is_array;
16
use function sprintf;
17

18
/**
19
 * Class UserGroupTransformer
20
 *
21
 * @package App\User
22
 */
23
class UserGroupTransformer implements DataTransformerInterface
24
{
25
    public function __construct(
26
        private readonly UserGroupResource $resource,
27
    ) {
28
    }
×
29

30
    /**
31
     * {@inheritdoc}
32
     *
33
     * Transforms an array of objects (UserGroup) to an array of strings (UserGroup id).
34
     *
35
     * @psalm-param array<int, string|UserGroup>|mixed $value
36
     *
37
     * @psalm-return array<int, string>
38
     */
39
    public function transform($value): array
40
    {
41
        $callback = static fn (UserGroup | Stringable $userGroup): string =>
×
42
            $userGroup instanceof UserGroup ? $userGroup->getId() : (string)$userGroup;
×
43

44
        return is_array($value) ? array_map($callback, $value) : [];
×
45
    }
46

47
    /**
48
     * {@inheritdoc}
49
     *
50
     * Transforms an array of strings (UserGroup id) to an array of objects (UserGroup).
51
     *
52
     * @psalm-param array<int, string>|mixed $value
53
     *
54
     * @throws Throwable
55
     *
56
     * @psalm-return array<int, UserGroup>|null
57
     */
58
    public function reverseTransform($value): ?array
59
    {
60
        return is_array($value)
×
61
            ? array_map(
×
62
                fn (string $groupId): UserGroup => $this->resource->findOne($groupId, false) ??
×
63
                    throw new TransformationFailedException(
×
64
                        sprintf('User group with id "%s" does not exist!', $groupId),
×
65
                    ),
×
66
                $value,
×
67
            )
×
68
            : null;
×
69
    }
70
}
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