maker-bundle icon indicating copy to clipboard operation
maker-bundle copied to clipboard

make:entity fails with entity name "Repository"

Open jzawadzki opened this issue 3 years ago • 3 comments

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:

  1. Fix the bug
  2. Block "Repository" as reserved keyword

jzawadzki avatar Sep 01 '21 09:09 jzawadzki

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 👍🏻

OskarStark avatar Sep 02 '21 08:09 OskarStark

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

jzawadzki avatar Sep 02 '21 13:09 jzawadzki

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?

jrushlow avatar Sep 03 '21 17:09 jrushlow