Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collection as reserved keywords #1389

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

StevenRenaux
Copy link
Contributor

@StevenRenaux StevenRenaux commented Oct 31, 2023

Related to #1380

In the generate method we call the Generator class and the method createClassNameDetails.

        $entityClassDetails = $generator->createClassNameDetails(
            $input->getArgument('name'),
            'Entity\\'
        );

And in this method we call the static method validateClassName of the Validator class.
In it we already have a check about the reserved keywords.

        $reservedKeywords = ['__halt_compiler', 'abstract', 'and', 'array',
            'as', 'break', 'callable', 'case', 'catch', 'class',
            'clone', 'const', 'continue', 'declare', 'default', 'die', 'do',
            'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor',
            'endforeach', 'endif', 'endswitch', 'endwhile', 'eval',
            'exit', 'extends', 'final', 'finally', 'fn', 'for', 'foreach', 'function',
            'global', 'goto', 'if', 'implements', 'include',
            'include_once', 'instanceof', 'insteadof', 'interface', 'isset',
            'list', 'match', 'namespace', 'new', 'or', 'print', 'private',
            'protected', 'public', 'readonly', 'require', 'require_once', 'return',
            'static', 'switch', 'throw', 'trait', 'try', 'unset',
            'use', 'var', 'while', 'xor', 'yield',
            'int', 'float', 'bool', 'string', 'true', 'false', 'null', 'void',
            'iterable', 'object', '__file__', '__line__', '__dir__', '__function__', '__class__',
            '__method__', '__namespace__', '__trait__', 'self', 'parent', 'collection',
        ];

Is this the best solution to avoid these dangerous/ambiguous class names?
Because this method is also called by the other makers.

Or do we need to add an additional verification in the entity maker?

@StevenRenaux StevenRenaux changed the title Add collection as reservedKeywords Add collection as reserved keywords Oct 31, 2023
@weaverryan
Copy link
Member

Yea... I see what you mean. I'm ok with putting it here. I have a hard time imagining someone trying to create a class called Collection with any maker other than make:entity.

@weaverryan
Copy link
Member

Thanks Steven!

@weaverryan weaverryan merged commit 968825e into symfony:main Oct 31, 2023
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants