Skip to content

[PropertyInfo] Allow nested collections #28012

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
Aug 2, 2018
Merged

Conversation

jderusse
Copy link
Member

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

When a multidimentional collection is defined (in a docblock) the extractor does not resolve the className deeply

#input
class Foo {
  /**
   * @var Baz[][]
   */
  public $bar;
}
# current result
builtinType: array
collectionValueType: 
  builtinType: object
  class: Baz[]
# FIX
builtinType: array
collectionValueType: 
  builtinType: array
  collectionValueType: 
    builtinType: object
    class: Baz

The 2.8 version has also that bug, but the methods have been moved to another class. Should I create an other PR for 2.8?

@ostrolucky
Copy link
Contributor

ostrolucky commented Jul 21, 2018

There is another change you left out

For:

/** @var mixed[][] */

before:

builtintype: array
collectionKeyType: null
collectionValueType: null

after:

builtintype: array
collectionKeyType:
  builtintype: int
collectionValueType: 
  builtintype: array

@jderusse
Copy link
Member Author

jderusse commented Jul 21, 2018

Hi @ostrolucky ,

I agreed, that I didn't handle the mixed[] the same way than before, but I think the new return is

builtintype: array
collectionKeyType:
  builtintype: int
collectionValueType: null

(because of line 92) can you please double check?

Which led to a different behavior for the field collectionKeyType because, this is what I would expect. And I though it was a bug too: Why int[], bool[], object[] will not return the same collectionKeyType than mixed[]?
Should I consider it has a BC break?

@ostrolucky
Copy link
Contributor

ostrolucky commented Jul 21, 2018

I double checked. Please write unit test for this.

@nicolas-grekas nicolas-grekas changed the title Allow multidimensional collection in property info [PropertyInfo] Allow multidimensional collection Jul 23, 2018
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Jul 23, 2018
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.

(for 2.8, PR welcome if the bug exists there also I suppose)

@@ -38,6 +38,7 @@ public function testGetProperties()
'bal',
'parent',
'collection',
'deepCollection',
Copy link
Member

Choose a reason for hiding this comment

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

A very minor comment: is there any reason for calling this deepCollection instead of nestedCollection? The nested one sounds more natural to me. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@ostrolucky
Copy link
Contributor

ostrolucky commented Jul 23, 2018

mixed[][] behavior not clarified. What's the consensus? Seems there is different behavior currently than expected by author

@ostrolucky
Copy link
Contributor

Also, not sure it's right to always use int for keyType, as there is no way to specify via docblock otherwise

@jderusse
Copy link
Member Author

jderusse commented Jul 24, 2018

I reverted changes on mixed[] as PhpDocumentor cast mixed[] to generic array => https://github.com/phpDocumentor/TypeResolver/blob/0.4.0/src/Types/Array_.php#L80-L82.

now mixed[] will return (as before)

builtintype: array
collectionKeyType: null
collectionValueType: null

@jderusse jderusse changed the title [PropertyInfo] Allow multidimensional collection [PropertyInfo] Allow nested collections Jul 24, 2018
@nicolas-grekas nicolas-grekas requested a review from dunglas July 25, 2018 08:22
fabpot added a commit that referenced this pull request Aug 2, 2018
This PR was merged into the 2.8 branch.

Discussion
----------

[PropertyInfo] Allow nested collections

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

Duplicate of #28012 for the 2.8 branche (as both code and test have been refactored between 2.8 and 3.x

Commits
-------

6331687 Allow multidimensional collection in property info
@fabpot
Copy link
Member

fabpot commented Aug 2, 2018

Thank you @jderusse.

@fabpot fabpot merged commit ce49036 into symfony:3.4 Aug 2, 2018
fabpot added a commit that referenced this pull request Aug 2, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

[PropertyInfo] Allow nested collections

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

When a multidimentional collection is defined (in a docblock) the extractor does not resolve the className deeply

```
#input
class Foo {
  /**
   * @var Baz[][]
   */
  public $bar;
}
```
```
# current result
builtinType: array
collectionValueType:
  builtinType: object
  class: Baz[]
```

```
# FIX
builtinType: array
collectionValueType:
  builtinType: array
  collectionValueType:
    builtinType: object
    class: Baz
```

The 2.8 version has also that bug, but the methods have been moved to another class. Should I create an other PR for 2.8?

Commits
-------

ce49036 Allow multidimensional collection in property info
@nicolas-grekas
Copy link
Member

@jderusse or anyone else: PropertyInfo 3.4 is red currently, could you have a look please?

@jderusse
Copy link
Member Author

jderusse commented Aug 3, 2018

cheking it

@jderusse
Copy link
Member Author

jderusse commented Aug 3, 2018

@nicolas-grekas shouldn't it be fixed by fe482cc ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 3, 2018

Looks like so. It wasn't passing locally, but I suppose that's because I didn't run composer update before... Sorry for the false alarm.

@nicolas-grekas
Copy link
Member

When merging into master, I added this commit to make tests pass: a5516fc

Please check and submit a PR if the patch should be improved.

This was referenced Aug 28, 2018
@jderusse jderusse deleted the fix-deep-array branch August 2, 2019 12:15
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