Skip to content

[Config] Enable cannotBeEmpty along with requiresAtLeastOneElement #20361

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

Closed
wants to merge 2 commits into from
Closed

[Config] Enable cannotBeEmpty along with requiresAtLeastOneElement #20361

wants to merge 2 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Oct 30, 2016

Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20356
License MIT
Doc PR reference to the documentation PR, if any

As @vudaltsov mentioned, we ignore any calls to ArrayNodeDefinition::cannotBeEmpty, which can lead to unexpected behavior. Imo. all subclasses should follow the base API.

@@ -117,9 +117,13 @@ public function addDefaultChildrenIfNoneSet($children = null)
* This method is applicable to prototype nodes only.
*
* @return ArrayNodeDefinition
*
* @deprecated Deprecated since version 3.2, to be removed in 4.0. Use cannotBeEmpty() instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be 3.3

@ro0NL
Copy link
Contributor Author

ro0NL commented Nov 5, 2016

Otherwise what about disallowing cannotBeEmpty like the numeric node does? https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Config/Definition/Builder/NumericNodeDefinition.php#L71

@javiereguiluz javiereguiluz added this to the 3.3 milestone Nov 7, 2016
@@ -372,7 +376,7 @@ protected function createNode()
$node->setKeyAttribute($this->key, $this->removeKeyItem);
}

if (true === $this->atLeastOne) {
if (true === $this->atLeastOne || false === $this->allowEmptyValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or given this bug, shouldn't we not fix it (to prevent any bc break), and deprecate cannotBeEmpty instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine either way... the numeric node does that actually.

Personally i'd favor Array::cannotBeEmpty over requiresAtLeastOneElement, but maybe that's just me :)

Maybe provide requiresAtLeastOneElement as an alias to cannotBeEmpty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd favor simplicity her, taking history into account, thus stick to requiresAtLeastOneElement and make the PR as small as possible. It's not like requiresAtLeastOneElement is a bad name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Deprecating cannotBeEmpty means it should throw in 4.0 right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just be removed if we can

Copy link
Contributor Author

@ro0NL ro0NL Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Removed the deprecation (worth it?) so both requiresAtLeastOneElement and cannotBeEmpty act the same. We cannot really deprecate/remove cannotBeEmpty as it comes from the base class (not sure this should be reversed in any way from a sub class).

So either deprecate requiresAtLeastOneElement in favor of cannotBeEmpty or support both like i did.

Or indeed throw from ArrayNode::cannotBeEmpty.. but im not sure it's worth the hassle.

@@ -117,9 +117,13 @@ public function addDefaultChildrenIfNoneSet($children = null)
* This method is applicable to prototype nodes only.
*
* @return ArrayNodeDefinition
*
* @deprecated Deprecated since version 3.3, to be removed in 4.0. Use cannotBeEmpty() instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deprecated Deprecated

@nicolas-grekas
Copy link
Member

Status: needs work

@ro0NL
Copy link
Contributor Author

ro0NL commented Mar 27, 2017

Tests added.

or given this bug, shouldn't we not fix it (to prevent any bc break)

Agree. Not sure we should do anything on lower branches given "ignored method call" vs. "crashing method call".

Right now both requiresAtLeastOneElement and cannotBeEmpty work the same, as expected probably. And im also not sure we should change that on lower branches...

Status: needs review

@ro0NL ro0NL changed the title [Config] Favor cannotBeEmpty instead of requiresAtLeastOneElement [Config] Enable cannotBeEmpty along with requiresAtLeastOneElement Mar 27, 2017
@ro0NL
Copy link
Contributor Author

ro0NL commented Mar 31, 2017

@fabpot in case you missed it (failures unrelated). Let me know if i should add a changelog or so.

@nicolas-grekas nicolas-grekas changed the base branch from master to 3.4 July 12, 2017 07:19
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
@ro0NL can you please rebase to trigger tests again so that we can see them green?

@ro0NL
Copy link
Contributor Author

ro0NL commented Jul 12, 2017

All good. Failure unrelated.

@nicolas-grekas
Copy link
Member

ping @ogizanagi @fabpot

@fabpot
Copy link
Member

fabpot commented Aug 5, 2017

Thank you @ro0NL.

fabpot added a commit that referenced this pull request Aug 5, 2017
…stOneElement (ro0NL)

This PR was squashed before being merged into the 3.4 branch (closes #20361).

Discussion
----------

[Config] Enable cannotBeEmpty along with requiresAtLeastOneElement

| Q | A |
| --- | --- |
| Branch? | "master" |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes
| Fixed tickets | #20356 |
| License | MIT |
| Doc PR | reference to the documentation PR, if any |

As @vudaltsov mentioned, we ignore any calls to `ArrayNodeDefinition::cannotBeEmpty`, which can lead to unexpected behavior. Imo. all subclasses should follow the base API.

Commits
-------

d40e7e4 [Config] Enable cannotBeEmpty along with requiresAtLeastOneElement
@fabpot fabpot closed this Aug 5, 2017
This was referenced Oct 18, 2017
@ro0NL ro0NL deleted the config/allow-empty branch October 19, 2017 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants