Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1408436

Browse files
authored
fix: factory template formatting (#1110)
* Fix Factory template formatting Because of how php tag works the output of `make:factory` generates some "not so pretty" PHP code. It lacks some carriage returns that place `Override` attributes where they shouldn't be and has more spaces than needed in some places. Generated code: ```php <?php namespace App\Factory; use App\Entity\User; use App\Repository\UserRepository; use Doctrine\ORM\EntityRepository; use Zenstruck\Foundry\Persistence\PersistentObjectFactory; use Zenstruck\Foundry\Persistence\Proxy; use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator; /** * @extends PersistentObjectFactory<User> */ final class UserFactory extends PersistentObjectFactory{ /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services * * @todo inject services if required */ public function __construct() { } #[\Override] public static function class(): string { return User::class; } /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories * * @todo add your default values here */ #[\Override] protected function defaults(): array|callable { return [ 'name' => self::faker()->text(10), ]; } /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization */ #[\Override] protected function initialize(): static { return $this // ->afterInstantiate(function(User $user): void {}) ; } } ``` * Remove parent constructor call in Factory class Removed unnecessary parent constructor call in the Factory class.
1 parent b8f8909 commit 1408436

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

skeleton/Factory.tpl.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
?>
2727
*/
28-
final class <?php echo $class_name; ?> extends <?php echo $makeFactoryData->getFactoryClassShortName(); ?>
28+
final class <?php echo $class_name; ?> extends <?php echo $makeFactoryData->getFactoryClassShortName(); ?><?= "\n" ?>
2929
{
3030
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
3131
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services
@@ -36,19 +36,19 @@ public function __construct()
3636
{
3737
}
3838

39-
<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
39+
<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?= "\n" ?><?php endif ?>
4040
public static function class(): string
4141
{
4242
return <?php echo $makeFactoryData->getObjectShortName(); ?>::class;
4343
}
4444

45-
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
45+
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
4646
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories
4747
*
4848
* @todo add your default values here
4949
*/
50-
<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
51-
protected function defaults(): array<?php if ($makeFactoryData->shouldAddHints()): ?>|callable<?php endif ?>
50+
<?php endif ?><?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?= "\n" ?><?php endif ?>
51+
protected function defaults(): array<?php if ($makeFactoryData->shouldAddHints()): ?>|callable<?= "\n" ?><?php endif ?>
5252
{
5353
return [
5454
<?php
@@ -59,10 +59,10 @@ protected function defaults(): array<?php if ($makeFactoryData->shouldAddHints()
5959
];
6060
}
6161

62-
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
62+
<?php if ($makeFactoryData->shouldAddHints()): ?> /**
6363
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization
6464
*/
65-
<?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?php endif ?>
65+
<?php if ($makeFactoryData->shouldAddOverrideAttributes()): ?> #[\Override]<?= "\n" ?><?php endif ?>
6666
protected function initialize(): static
6767
{
6868
return $this

0 commit comments

Comments
 (0)