• 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

68.0
/src/General/Infrastructure/Repository/Traits/RepositoryWrappersTrait.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\General\Infrastructure\Repository\Traits;
6

7
use App\General\Domain\Rest\UuidHelper;
8
use Doctrine\ORM\EntityManager;
9
use Doctrine\ORM\Mapping\ClassMetadataInfo;
10
use Doctrine\ORM\QueryBuilder;
11
use Ramsey\Uuid\Exception\InvalidUuidStringException;
12
use UnexpectedValueException;
13

14
use function preg_replace;
15

16
/**
17
 * Class RepositoryWrappersTrait
18
 *
19
 * @package App\General
20
 */
21
trait RepositoryWrappersTrait
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getReference(string $id, ?string $entityManagerName = null): ?object
27
    {
28
        try {
29
            $referenceId = UuidHelper::fromString($id);
126✔
30
        } catch (InvalidUuidStringException) {
3✔
31
            $referenceId = $id;
3✔
32
        }
33

34
        return $this->getEntityManager($entityManagerName)->getReference($this->getEntityName(), $referenceId);
126✔
35
    }
36

37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @psalm-return array<string, array<string, mixed>>
41
     */
42
    public function getAssociations(?string $entityManagerName = null): array
43
    {
44
        return $this->getClassMetaData($entityManagerName)->getAssociationMappings();
×
45
    }
46

47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getClassMetaData(?string $entityManagerName = null): ClassMetadataInfo
51
    {
52
        return $this->getEntityManager($entityManagerName)->getClassMetadata($this->getEntityName());
×
53
    }
54

55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getEntityManager(?string $entityManagerName = null): EntityManager
59
    {
60
        $manager = $entityManagerName
142✔
61
            ? $this->managerRegistry->getManager($entityManagerName)
×
62
            : $this->managerRegistry->getManagerForClass($this->getEntityName());
142✔
63

64
        if (!($manager instanceof EntityManager)) {
142✔
65
            throw new UnexpectedValueException(
×
66
                'Cannot get entity manager for entity \'' . $this->getEntityName() . '\''
×
67
            );
×
68
        }
69

70
        if ($manager->isOpen() === false) {
142✔
71
            $this->managerRegistry->resetManager($entityManagerName);
×
72
            $manager = $this->getEntityManager($entityManagerName);
×
73
        }
74

75
        return $manager;
142✔
76
    }
77

78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function createQueryBuilder(
82
        ?string $alias = null,
83
        ?string $indexBy = null,
84
        ?string $entityManagerName = null
85
    ): QueryBuilder {
86
        $alias ??= 'entity';
133✔
87
        $alias = (string)preg_replace('#[\W]#', '', $alias);
133✔
88
        $indexBy = $indexBy !== null ? (string)preg_replace('#[\W]#', '', $indexBy) : null;
133✔
89

90
        // Create new query builder
91
        return $this
133✔
92
            ->getEntityManager($entityManagerName)
133✔
93
            ->createQueryBuilder()
133✔
94
            ->select($alias)
133✔
95
            ->from($this->getEntityName(), $alias, $indexBy);
133✔
96
    }
97
}
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

© 2025 Coveralls, Inc