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

tito10047 / type-safe-id-bundle / 23154394392

15 Mar 2026 02:28PM UTC coverage: 69.912%. Remained the same
23154394392

push

github

web-flow
Merge pull request #1 from tito10047/test

Test

11 of 36 new or added lines in 4 files covered. (30.56%)

5 existing lines in 1 file now uncovered.

79 of 113 relevant lines covered (69.91%)

12.05 hits per line

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

84.48
/src/IdEntityGenerator.php
1
<?php
2

3
namespace Tito10047\TypeSafeIdBundle;
4

5
use Doctrine\ORM\QueryBuilder;
6
use Symfony\Bridge\Doctrine\Types\AbstractUidType;
7
use Symfony\Bridge\Doctrine\Types\UlidType;
8
use Symfony\Bridge\Doctrine\Types\UuidType;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Bundle\MakerBundle\Generator;
11
use Symfony\Bundle\MakerBundle\Maker\Common\EntityIdTypeEnum;
12
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
13
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
14
use Symfony\Component\Uid\Ulid;
15
use Symfony\Component\Uid\Uuid;
16
use Tito10047\TypeSafeIdBundle\AbstractIntIdType;
17

18
class IdEntityGenerator extends Generator {
19

20

21
        /**
22
         * @noinspection PhpMissingParentConstructorInspection
23
         */
24
        private ?string $classNameId = null;
25
        private ?EntityIdTypeEnum   $idType = null;
26

27
        public function __construct(
28
                private readonly Generator $generator,
29
        ) {
30
        }
18✔
31

32
        public static function getControllerBaseClass(): ClassNameDetails {
33
                return new ClassNameDetails(AbstractController::class, '\\');
×
34
        }
35

36
        /**
37
         * @param array<string,mixed> $variables
38
         * @throws \Exception
39
         */
40
        public function generateClass(string $className, string $templateName, array $variables = []): string {
41
                /** @var UseStatementGenerator $useGenerator */
42
                $useGenerator = $variables['use_statements']??null;
18✔
43
                $this->idType ??= $variables['id_type'];
18✔
44
                if ($templateName === 'doctrine/Entity.tpl.php') {
18✔
45
                        $templateName = __DIR__ . '/../templates/extension/maker/Entity.tpl.php';
18✔
46

47
                        $this->classNameId = str_replace('\Entity\\', '\EntityId\\', $className)."Id";
18✔
48
                        $classNameIdType = $this->classNameId."Type";
18✔
49
                        $useStatements = new  UseStatementGenerator([]);
18✔
50
                        if (($variables['id_type']??null) === EntityIdTypeEnum::UUID) {
18✔
51
                                $useStatements->addUseStatement(Uuid::class);
6✔
52
                        } elseif (($variables['id_type']??null) === EntityIdTypeEnum::ULID) {
12✔
53
                                $useStatements->addUseStatement(Ulid::class);
6✔
54
                        }
55
                        $idVariables = $variables;
18✔
56
                        $idVariables['id_type'] ??= null;
18✔
57
                        $idVariables["use_statements"] = $useStatements;
18✔
58
                        $this->generator->generateClass(
18✔
59
                                $this->classNameId,
18✔
60
                                 __DIR__ . '/../templates/extension/maker/TypeId.tpl.php',
18✔
61
                                $idVariables
18✔
62
                        );
18✔
63

64
                        $typeVariables = $variables;
18✔
65
                        $typeVariables['id_type'] ??= null;
18✔
66
                        $useStatements = new  UseStatementGenerator([]);
18✔
67
                        $useStatements->addUseStatement($this->classNameId);
18✔
68
                        if (($variables['id_type']??null) === EntityIdTypeEnum::UUID || ($variables['id_type']??null) === EntityIdTypeEnum::ULID) {
18✔
69
                                $useStatements->addUseStatement(AbstractUidType::class);
12✔
70
                        } else {
71
                                $useStatements->addUseStatement(AbstractIntIdType::class);
6✔
72
                        }
73
                        $typeVariables["use_statements"] = $useStatements;
18✔
74
                        $parts = explode('\\', $this->classNameId);
18✔
75
                        $typeVariables["id_class"] = array_pop($parts);;
18✔
76
                        $this->generator->generateClass(
18✔
77
                                $classNameIdType,
18✔
78
                                __DIR__ . '/../templates/extension/maker/TypeIdType.tpl.php',
18✔
79
                                $typeVariables
18✔
80
                        );
18✔
81

82

83
                        $variables["use_statements"]->addUseStatement($this->classNameId);
18✔
84
                        $variables["use_statements"]->addUseStatement($classNameIdType);
18✔
85
                }
86
                if ($templateName === 'doctrine/Repository.tpl.php') {
18✔
87
                        $templateName = __DIR__ . '/../templates/extension/maker/Repository.tpl.php';
18✔
88
                        $variables['include_example_comments'] = false;
18✔
89
                        $variables['id_type'] = $this->idType;
18✔
90
                        $useGenerator->addUseStatement(QueryBuilder::class);
18✔
91
                        $useGenerator->addUseStatement($this->classNameId);
18✔
92

93
                }
94

95
                return $this->generator->generateClass($className, $templateName, $variables);
18✔
96
        }
97

98
        /**
99
         * @param array<string,mixed> $variables
100
         */
101
        public function generateFile(string $targetPath, string $templateName, array $variables = []): void {
UNCOV
102
                $this->generator->generateFile($targetPath, $templateName, $variables);
×
103
        }
104

105
        public function dumpFile(string $targetPath, string $contents): void {
UNCOV
106
                $this->generator->dumpFile($targetPath, $contents);
×
107
        }
108

109
        public function getFileContentsForPendingOperation(string $targetPath): string {
110
                return $this->generator->getFileContentsForPendingOperation($targetPath);
×
111
        }
112

113
        public function createClassNameDetails(
114
                string $name, string $namespacePrefix, string $suffix = '', string $validationErrorMessage = ''): ClassNameDetails {
115
                return $this->generator->createClassNameDetails($name, $namespacePrefix, $suffix,
18✔
116
                        $validationErrorMessage);
18✔
117
        }
118

119
        public function getRootDirectory(): string {
UNCOV
120
                return $this->generator->getRootDirectory();
×
121
        }
122

123
        public function hasPendingOperations(): bool {
124
                return $this->generator->hasPendingOperations();
18✔
125
        }
126

127
        public function writeChanges() {
128
                $this->generator->writeChanges();
18✔
129
        }
130

131
        public function getRootNamespace(): string {
UNCOV
132
                return $this->generator->getRootNamespace();
×
133
        }
134

135
        /**
136
         * @param string[] $parameters
137
         */
138
        public function generateController(string $controllerClassName, string $controllerTemplatePath, array $parameters = []): string {
UNCOV
139
                return $this->generator->generateController($controllerClassName, $controllerTemplatePath,
×
140
                        $parameters);
×
141
        }
142

143
        /**
144
         * @param array<string,mixed> $variables
145
         */
146
        public function generateTemplate(string $targetPath, string $templateName, array $variables = []): void {
147
                $this->generator->generateTemplate($targetPath, $templateName, $variables);
×
148
        }
149

150
        /**
151
         * @return string[]
152
         */
153
        public function getGeneratedFiles(): array {
154
                return $this->generator->getGeneratedFiles();
18✔
155
        }
156

157

158

159
}
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