symfony / maker-bundle

Symfony Maker Bundle
https://symfony.com/
MIT License
3.36k stars 405 forks source link

make:crud tries to use the wrong class when the specified class name is the first part of another class name #141

Open thomasisok opened 6 years ago

thomasisok commented 6 years ago

For example, I used make:crud to generate a controller for my entity SampleClassification. Then I created another entity Sample, but when I tried to make:crud for Sample I got this error:

[ERROR] The file "src/Controller/SampleClassificationController.php" can't be generated because it already exists.

thomasisok commented 6 years ago

I just discovered that it only happens when I don't pass the class name as part of the make:crud command, but add it at the The class name of the entity to create CRUD prompt. If I just do php bin/console make:crud Sample, it works as I expected.

sadikoff commented 6 years ago

@thomasisok maybe there is a problem with autocomplete? I'll try to reproduce your env to test.

weaverryan commented 6 years ago

@thomasisok yea, it is possible that when you're typing Sample, the console command is auto-completing this to SampleClassification. Can you double-check that and make sure that only Sample is entered? This is one of the cases when the auto-completion can be annoying.

cronk1986 commented 6 years ago

Hello,

I don't know if this is the correct place for requesting... but I would like to know follow:

How can I generate a crud in a custom bundle? The old syntax doesn't work, ie: bin/console make:crud MyCustomBundle:MyCustomEntity

thank you!

thomasisok commented 6 years ago

@weaverryan Yes, I've experimented with it a bit and I'm certain I'm only entering Sample. If I enter php bin/console make:crud and then enter Sample at the following prompt, it apparently autocompletes it to SampleClassification, but if I give the class in the initial command php bin/console make:crud Sample it doesn't. I don't know if this is intended behavior or not, and it isn't really that much of a problem now that I know how to avoid it. Is there any more info I need to give here? This is my first time reporting anything so I'm not sure.

weaverryan commented 6 years ago

Hmmm. Thanks for the info. Maybe, could you take a screenshot of when you answer the question interactively with “Sample” (like: right befor you hit Enter to answer the question)?

weaverryan commented 6 years ago

@cronk1986 you can enter the full class name in most cases. So, when you’re asked the question, try typing \My\CustomBundle\Entity\Foo

If your entity name starts with a slash, we assume you are pointing to an exact entity. To pass this as an argument, all the slashes will need to be double slashes.

javiereguiluz commented 6 years ago

This is because of how Symfony autocomplete works. If you have SampleClassification and type Sample + <Enter> ... Symfony understands the <Enter> as "yes, autocomplete this to SampleClassification" instead of "yes, I've written Sample and that's what I want to use":

autocomplete-issue

The only working solution I can come up is to add a whitespace after Sample and press <Enter>:

autocomplete-issue-solution

sadikoff commented 6 years ago

@javiereguiluz maybe there is a way to sort autocomplete values by length to evade this situation? I'll try to investigate this situation.

thomasisok commented 6 years ago

@javiereguiluz Oh, that's interesting. I don't see the autocomplete happening like that. Is that because I'm on Windows? It would have been a lot more obvious what was happening to begin with if I had seen it autocompleting.

sadikoff commented 6 years ago

@thomasisok by the way I'm on windows too, and I don't have this problem.

thomasisok commented 6 years ago

@sadikoff You can see it autocompleting as you type like in that gif? I'm on Windows 7, and don't see the autocomplete, either in cmd or powershell.

sadikoff commented 6 years ago

No I don't have autocomplete, but when I type Sample it works with Sample entity!