Skip to content

Add Inflector component (from StringUtil of PropertyAccess) #18260

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

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

teohhanhui
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? no
Fixed tickets N/A
License MIT
Doc PR N/A

As proposed by @dunglas here: #18166 (comment)

This will help us fix #18166

<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
Copy link
Member

Choose a reason for hiding this comment

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

should be current, not 4.1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Every other component uses 4.1 though. Perhaps this should be addressed in a separate PR (if it's an issue)?

@teohhanhui teohhanhui force-pushed the inflector-component branch from d85bcad to 9695e78 Compare March 22, 2016 09:47
@stof
Copy link
Member

stof commented Mar 22, 2016

We need to keep some legacy test for the StringUtil class

@@ -0,0 +1,19 @@
Copyright (c) 2012-2016 Fabien Potencier
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The year is 2012 based on 7837f50

@teohhanhui
Copy link
Contributor Author

@stof

We need to keep some legacy test for the StringUtil class

Should the test be duplicated?

@stof
Copy link
Member

stof commented Mar 22, 2016

Should the test be duplicated?

no need to duplicate the whole tests (as the new component is tested). But we at least need a simple test, which would catch mistakes in the BC class

@javiereguiluz
Copy link
Member

What about using Doctrine Inflector library instead of creating a new component?

@teohhanhui
Copy link
Contributor Author

@javiereguiluz To me that'd be preferable too. But we need to use the same inflector for both PropertyAccess and PropertyInfo, according to @dunglas: #18166 (comment)

And if we switch both to the Doctrine Inflector, how should we handle the BC break?

@linaori
Copy link
Contributor

linaori commented Mar 22, 2016

I think it would be preferable for the community to use only 1 inflector library. Would it be an idea to use the doctrine variant instead and start patching that one to cover more use-cases when needed?

@teohhanhui
Copy link
Contributor Author

How do we handle the BC break? Or would it not be considered a BC break? 😜

@linaori
Copy link
Contributor

linaori commented Mar 22, 2016

@teohhanhui I don't see why it would be. You can leave the deprecation as is and leave the tests as is. If the tests fail, you can patch those missing use-cases in the doctrine inflector. The only BC break would be tests failing because the doctrine inflector misses cases, but you will find out by hooking it up.

@teohhanhui
Copy link
Contributor Author

@iltar I'm thinking BC breaks for applications due to different result of the singularization. It seems impossible for us to catch them all...

@teohhanhui
Copy link
Contributor Author

But alas, it'd be for the best. What do you think, @dunglas?

@javiereguiluz
Copy link
Member

I'm thinking BC breaks for applications due to different result of the singularization.

How could be any difference if both libraries supposedly do the same: transform English words into/from singular/plural?

@stof
Copy link
Member

stof commented Mar 22, 2016

How could be any difference if both libraries supposedly do the same: transform English words into/from singular/plural?

Given that the conversion rules are quite complex, they may behave differently for some cases (common rules should work fine, but the component would be useless if the rule was as simple as removing the final s)

@teohhanhui
Copy link
Contributor Author

If the application previously used the wrong singular form which matches what is produced by StringUtil::singularify, it'll stop working once we switch to Doctrine Inflector (given that the singular form is now correct); and vice versa, what used to be correct could now be wrong.

It's not really possible for us to ensure consistent before/after results. Now the question is whether this is part of our BC promise (of course, surprises like this would still be unwelcome and annoying for an application developer).

@linaori
Copy link
Contributor

linaori commented Mar 22, 2016

Luckily we have tests to verify the symfony variant still works, if they pass, no problem. If they fail: patch the inflector on doctrine's side.

@stof
Copy link
Member

stof commented Mar 22, 2016

The compatibility test between both library would be as follow:

  • run the Symfony StringUtil testcases against the doctrine/inflector implementation
  • run the doctrine/inflector testcases against the StringUtil implementation (for relevant tests of course, as doctrine/inflector contains more methods than just singularify).

Test failures there would show us known incompatibilities (we may still have incompatibilities in things not covered by any of the testsuites). This would help us to make the decision.

@teohhanhui
Copy link
Contributor Author

run the Symfony StringUtil testcases against the doctrine/inflector implementation

There are many failures: https://travis-ci.org/teohhanhui/symfony/jobs/117700871#L4206-L4791

And there's a bigger problem... Doctrine Inflector's singularize method doesn't support multiple singular forms (even though StringUtil mostly returned bogus results, but there are many valid cases for this...)

edit: Yes, there are still some valid use cases: https://www.quora.com/What-is-the-plural-of-axis

@teohhanhui
Copy link
Contributor Author

After clean-up: https://travis-ci.org/teohhanhui/symfony/jobs/117721231#L4099-L4348

There are still a number of failures, and a few that we have no real way of fixing in the Doctrine Inflector (multiple words with the same plural form):

  • axes => axe, ax, axis
  • bases => base, basis

@stof
Copy link
Member

stof commented Mar 22, 2016

There are still a number of failures, and a few that we have no real way of fixing in the Doctrine Inflector (multiple words with the same plural form):

And this is the difference between the doctrine inflector and the Symfony StringUtil: the doctrine inflector aims to provide a single singular string (which make sense as their primary usage of the inflector is generating method names during code generation, so they must settle on a single singular), while the goal of the StringUtil is to find all potential singular, to be able to call the method named by the developer with one of them.

and this difference of goal of the project is probably the main reason why we won't be able to switch to doctrine/inflector (as they won't change the focus of the Doctrine project just to allow us to use it)

@teohhanhui
Copy link
Contributor Author

@stof It looks like I have to continue with this PR then...

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

@teohhanhui Do you think you can finish (not sure what's left) this PR is the next couple of days? I'd like to get this in for 3.1 as it seems quite easy to acheive. Marking the whole component as being internal also gives us the opportunity to add more or even drop it if we find a better replacement in the meantime.

@teohhanhui
Copy link
Contributor Author

What else do I need to do, other than adding @internal to the classes and methods?

@teohhanhui teohhanhui force-pushed the inflector-component branch from 11f5c30 to 8c78b2c Compare March 31, 2016 06:33
@teohhanhui
Copy link
Contributor Author

Marked as internal and added a disclaimer in the README

@teohhanhui teohhanhui force-pushed the inflector-component branch 3 times, most recently from 8d9de9b to 10e2771 Compare March 31, 2016 06:42
@teohhanhui
Copy link
Contributor Author

Rebased.

@teohhanhui teohhanhui force-pushed the inflector-component branch from 10e2771 to 0c69e72 Compare March 31, 2016 06:52
@@ -0,0 +1,19 @@
Inflector Component
======================
Copy link
Member

Choose a reason for hiding this comment

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

Extra =s here

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

👍 (after the minor comments have been fixed)

@teohhanhui teohhanhui force-pushed the inflector-component branch from 0c69e72 to 9dbc0b4 Compare March 31, 2016 07:20
/**
* Creates singulars from plurals.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated Deprecated since version 3.1, to be removed in 4.0. Use {@see \Doctrine\Common\Inflector\Inflector} instead.
Copy link
Member

Choose a reason for hiding this comment

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

Telling people to use Doctrine Inflector does not make sense here as the feature is not the same. And in fact, we are creating a new component exactly for this reason: we cannot use Doctrine inflector. So, the recommendation should be to use the new component instead.

@teohhanhui teohhanhui force-pushed the inflector-component branch from 9dbc0b4 to 8abebf6 Compare March 31, 2016 07:36
@dunglas
Copy link
Member

dunglas commented Mar 31, 2016

👍

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

Thank you @teohhanhui.

@fabpot fabpot merged commit 8abebf6 into symfony:master Mar 31, 2016
fabpot added a commit that referenced this pull request Mar 31, 2016
…cess) (teohhanhui)

This PR was merged into the 3.1-dev branch.

Discussion
----------

Add Inflector component (from StringUtil of PropertyAccess)

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | no
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

As proposed by @dunglas here: #18166 (comment)

This will help us fix #18166

Commits
-------

8abebf6 Add Inflector component (from StringUtil of PropertyAccess)
@flip111
Copy link
Contributor

flip111 commented Apr 5, 2016

Is/can this component be used for #18149 ?

@teohhanhui teohhanhui deleted the inflector-component branch May 9, 2016 05:44
@fabpot fabpot mentioned this pull request May 13, 2016
dunglas added a commit that referenced this pull request Jun 7, 2016
…glas)

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

Discussion
----------

[PropertyInfo] Support singular adder and remover

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18166
| License       | MIT
| Doc PR        | n/a

Fix #18166 with only a soft dependency to the PropertyAccess component. If #18260 is accepted, this PR can be reworked to use this new component, in the meantime it fixes the problem with a soft dependency.

I don't now if it should be considered as a bug fix (and then merged in 2.8) or as a new feature. It's technically a bug fix but I'm not sure that introducing a new soft dependency is acceptable if older branches. What do you think @symfony/deciders?

Commits
-------

4cbb60c [PropertyInfo] Support singular adder and remover
nicolas-grekas added a commit that referenced this pull request May 21, 2017
…class (xabbuh)

This PR was merged into the 3.2 branch.

Discussion
----------

[PropertyAccess] document deprecation of the StringUtil class

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18260
| License       | MIT
| Doc PR        |

Commits
-------

f00c47a document deprecation of the StringUtil class
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.

[PropertyInfo] Singularize array mutator in ReflectionExtractor
8 participants