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

[Config] Provide shorthand methods for ArrayNodeDefinition::prototype() #20921

Closed
skafandri opened this issue Dec 14, 2016 · 1 comment
Closed

Comments

@skafandri
Copy link
Contributor

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version master

ArrayNodeDefinition::prototype() returns a NodeDefinition. However in reality it returns an IntegerNodeDefinition, ArrayNodeDefinition and so on.

This makes the last line of the following code ->max(10) not recognizable by IDEs and with a bit TreeBuilder is can become annoying

$node = new ArrayNodeDefinition('name');
$node
    ->prototype('integer')
    ->max(10);

I propose to provide shorthand methods for the standard node types (variable, scalar, boolean, integer, float, array, enum)

So the previous snippet could be written as

$node = new ArrayNodeDefinition('name');
$node
    ->prototypeInteger()
    ->max(10);

As a result, your IDE will recognize that it returns NumericNodeDefinition and can follow the call.

@arnaspet
Copy link

I think it's too much verbosity. 100 lines of code only for ide support is too much.
also i guess if you really want ide supportm you could do phpDoc like this

    /**
     * Sets a prototype for child nodes.
     *
     * @param string $type the type of node
     *
     * @return IntergerDefinition|ArrayDefinition| ScalarNodeDefinition // you get the point
     */
    public function prototype($type)
    {
...

but again, you would need to support those comments, if any NodeDefinition class would be created, you would forget to update this comment

@fabpot fabpot closed this as completed Dec 19, 2016
fabpot added a commit that referenced this issue Dec 19, 2016
…eDefinition::pr… (skafandri)

This PR was squashed before being merged into the 3.3-dev branch (closes #20923).

Discussion
----------

#20921 [Config] Provide shorthand methods for ArrayNodeDefinition::pr…

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20921
| License       | MIT

Commits
-------

22b8490 #20921 [Config] Provide shorthand methods for ArrayNodeDefinition::pr…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants