maker-bundle
maker-bundle copied to clipboard
make:entity fails with entity name "Repository"
I know that Repository isn't THE BEST name for an entity, but I found that make:entity have problem with generation of such.
Maker creates Repository called Repository instead of RepositoryRepository and because of that, their use sections conflicts (same name of Entity and Repository)
Steps to reproduce:
symfony new test;
cd test;
composer req orm;
composer req maker;
php bin/console make:entity Repository
Result:
PHP Fatal error: Cannot declare class App\Entity\Repository because the name is already in use in /home/jerzy/test/src/Entity/Repository.php on line 11
I see two possible solutions:
- Fix the bug
- Block "Repository" as reserved keyword
I would propose to fix the bug, to me Repository is a valid word. For example when working with code which handles GitHub repositories or anything else.
RepositoryRepository is the correct repository name.
Plus we should add a testcase 👍🏻
In the meantime I found the cause: https://github.com/symfony/maker-bundle/blob/main/src/Str.php#L36
/**
* Ensures that the given string ends with the given suffix. If the string
* already contains the suffix, it's not added twice. It's case-insensitive
* (e.g. value: 'Foocommand' suffix: 'Command' -> result: 'FooCommand').
*/
public static function addSuffix(string $value, string $suffix): string
I agree w/ @OskarStark - adding Repository as a "reserved word" is not ideal and will lead to problems. e.g. you can create a User::class entity, but using the word user for a property in a relation (Members::getUsers()) causes problems in some setups..
Let's fix the actual problem instead. @jzawadzki , are you up to submitting a PR?