Skip to content

Commit a39caed

Browse files
authored
Do not use leading \ for FQCN's (#2)
It's not needed since the file is not namespaced.
1 parent 5b4c8e2 commit a39caed

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ return static function (ContainerConfigurator $configurator) : void {
147147

148148
$services->set(
149149
'app.feature_service',
150-
\App\Service\FeatureService::class,
150+
App\Service\FeatureService::class,
151151
)
152152
->args(
153153
[
@@ -157,7 +157,7 @@ return static function (ContainerConfigurator $configurator) : void {
157157

158158
$services->set(
159159
'app.handler_registry',
160-
\App\Service\HandlerRegistry::class,
160+
App\Service\HandlerRegistry::class,
161161
)
162162
->args(
163163
[
@@ -167,13 +167,13 @@ return static function (ContainerConfigurator $configurator) : void {
167167

168168
$services->set(
169169
'app.logger',
170-
\Psr\Log\LoggerInterface::class,
170+
Psr\Log\LoggerInterface::class,
171171
)
172172
->autowire();
173173

174174
$services->set(
175175
'app.mailer',
176-
\App\Service\MailerService::class,
176+
App\Service\MailerService::class,
177177
)
178178
->args(
179179
[
@@ -198,7 +198,7 @@ return static function (ContainerConfigurator $configurator) : void {
198198

199199
$services->set(
200200
'app.request_listener',
201-
\App\EventListener\RequestListener::class,
201+
App\EventListener\RequestListener::class,
202202
)
203203
->tag(
204204
'kernel.event_listener',
@@ -210,7 +210,7 @@ return static function (ContainerConfigurator $configurator) : void {
210210

211211
$services->set(
212212
'app.user_handler',
213-
\App\Handler\UserHandler::class,
213+
App\Handler\UserHandler::class,
214214
)
215215
->tag('app.handler');
216216
};

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": "^8.4",
14-
"ruudk/code-generator": "^0.4.0",
14+
"ruudk/code-generator": "^0.4.5",
1515
"symfony/dependency-injection": "^7.3"
1616
},
1717
"require-dev": {

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SymfonyConfigCodeGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ private function export(mixed $input) : Generator
249249
yield from $this->dumpParam(substr($input, 1, -1));
250250
} elseif (is_string($input) && ($this->isFqcn($input) || $this->fqcnExists($input))) {
251251
// The class could not yet exist at compile time, so we need to check if it starts with TicketSwap\
252-
yield '\\' . $input . '::class';
252+
yield $input . '::class';
253253
} elseif (is_scalar($input)) {
254254
if (is_string($input) && preg_match('/^(?<fqcn>[\w\\\\]+) \$(?<name>\w+)$/', $input, $matches) === 1) {
255-
yield sprintf("\\%s::class . ' \$%s'", $matches['fqcn'], $matches['name']);
255+
yield sprintf("%s::class . ' \$%s'", $matches['fqcn'], $matches['name']);
256256
} else {
257257
yield var_export($input, true);
258258
}
@@ -275,7 +275,7 @@ private function export(mixed $input) : Generator
275275
} elseif ($input instanceof Definition) {
276276
yield from $this->dumpInlineService($input);
277277
} elseif ($input instanceof UnitEnum) {
278-
yield '\\' . $input::class . '::' . $input->name;
278+
yield $input::class . '::' . $input->name;
279279
} elseif (is_array($input)) {
280280
if ($input === []) {
281281
yield '[]';

tests/SymfonyConfigCodeGeneratorTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testDumpFileWithService() : void
109109
110110
$services->set(
111111
'app.logger',
112-
\Psr\Log\LoggerInterface::class,
112+
Psr\Log\LoggerInterface::class,
113113
)
114114
->autowire();
115115
};
@@ -147,7 +147,7 @@ public function testDumpFileWithServiceArguments() : void
147147
148148
$services->set(
149149
'app.mailer',
150-
\App\Mailer\MailerService::class,
150+
App\Mailer\MailerService::class,
151151
)
152152
->args(
153153
[
@@ -189,7 +189,7 @@ public function testDumpFileWithMethodCalls() : void
189189
190190
$services->set(
191191
'app.listener',
192-
\App\EventListener\UserListener::class,
192+
App\EventListener\UserListener::class,
193193
)
194194
->call(
195195
'setLogger',
@@ -237,7 +237,7 @@ public function testDumpFileWithTags() : void
237237
238238
$services->set(
239239
'app.event_listener',
240-
\App\EventListener\RequestListener::class,
240+
App\EventListener\RequestListener::class,
241241
)
242242
->tag(
243243
'kernel.event_listener',
@@ -281,7 +281,7 @@ public function testDumpFileWithAutoconfigure() : void
281281
282282
$services->set(
283283
'app.command',
284-
\App\Command\ProcessCommand::class,
284+
App\Command\ProcessCommand::class,
285285
)
286286
->tag('console.command')
287287
->autoconfigure();
@@ -314,7 +314,7 @@ public function testDumpFileWithExpression() : void
314314
315315
$services->set(
316316
'app.service',
317-
\App\Service\DynamicService::class,
317+
App\Service\DynamicService::class,
318318
)
319319
->args(
320320
[
@@ -404,7 +404,7 @@ public function testDumpFileWithComplexService() : void
404404
405405
$services->set(
406406
'app.complex',
407-
\App\Service\ComplexService::class,
407+
App\Service\ComplexService::class,
408408
)
409409
->args(
410410
[
@@ -456,7 +456,7 @@ public function testDumpFileWithServiceDecoration() : void
456456
457457
$services->set(
458458
'app.mailer_decorator',
459-
\App\Mailer\DecoratedMailer::class,
459+
App\Mailer\DecoratedMailer::class,
460460
)
461461
->decorate('mailer');
462462
};
@@ -488,11 +488,11 @@ public function testDumpFileWithTypedReference() : void
488488
489489
$services->set(
490490
'app.handler',
491-
\App\Handler\MessageHandler::class,
491+
App\Handler\MessageHandler::class,
492492
)
493493
->args(
494494
[
495-
service(\Psr\Log\LoggerInterface::class . ' $logger'),
495+
service(Psr\Log\LoggerInterface::class . ' $logger'),
496496
],
497497
);
498498
};
@@ -527,11 +527,11 @@ public function testDumpFileWithServiceAlias() : void
527527
528528
$services->set(
529529
'app.custom_logger',
530-
\App\Logger\CustomLogger::class,
530+
App\Logger\CustomLogger::class,
531531
);
532532
533533
$services->alias(
534-
\Psr\Log\LoggerInterface::class,
534+
Psr\Log\LoggerInterface::class,
535535
'app.custom_logger',
536536
);
537537
};
@@ -567,7 +567,7 @@ public function testDumpFileWithEnvironmentSpecificService() : void
567567
if ($configurator->env() === 'dev') {
568568
$services->set(
569569
'app.debug_logger',
570-
\App\Logger\DebugLogger::class,
570+
App\Logger\DebugLogger::class,
571571
);
572572
}
573573
};
@@ -599,7 +599,7 @@ public function testDumpFileSkipsServiceContainer() : void
599599
600600
$services->set(
601601
'app.service',
602-
\App\Service\MyService::class,
602+
App\Service\MyService::class,
603603
);
604604
};
605605

0 commit comments

Comments
 (0)