Skip to content

Conversation

raalderink
Copy link
Contributor

For the InputBag::get, if you add a default string parameter, it will always return a string. This is new in Symfony 5.0.

Fixes issue #91

composer.json Outdated
"symfony/console": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/http-foundation": "^4.0",
"symfony/http-foundation": "^4.0|^5.0",
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? Doesn't seem related to the rest.

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 InputBag is new in Symfony 5, didn't exist in 4 yet, so to run the tests we need Symfony 5

Copy link
Member

Choose a reason for hiding this comment

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

There currently isn't a nice way to test it in a 3rd party package, so you can delete the file tests/Type/Symfony/input_bag_get.php which isn't very useful currently.

Copy link
Contributor Author

@raalderink raalderink Aug 14, 2020

Choose a reason for hiding this comment

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

Okay, fair, so just delete the test altogether?

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, I haven't noticed there's actually a way here in phpstan-symfony with the ExtensionTestCase :) I just thought you create the file input_bag_get.php and let PHPStan analyse it, but right now you're actually checking the return types which is great :) So feel free to add some tests that fail with mixed, string|null etc. and see how my suggested logic fixes that :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure what you want me too add there? The $default parameter can technically be mixed, however, anything other than a string will throw a deprecation notice. Besides, falling back on default will say string|null either way, no matter what you put in $default, so I'm not sure if it would matter. I'm fine with adding other types to the test but the result will be the same :P

Copy link
Member

Choose a reason for hiding this comment

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

mixed means that it can be a string or null and we can't be sure, so the return type also has to be string|null. I just want to test the extension for mixed and string|null types as the second parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR updated, I think that's what you were looking for?

Copy link
Member

Choose a reason for hiding this comment

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

Approximately :) Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

@ruudk
Copy link
Contributor

ruudk commented Oct 20, 2020

@raalderink Anything I can do to help this PR get merged? I'm having the same issue while upgrading to Symfony 5.

@ruudk
Copy link
Contributor

ruudk commented Oct 20, 2020

Created a PR on your fork to get rid of the failing test. raalderink#1

@raalderink
Copy link
Contributor Author

@ruudk Thanks, I had lost track of this as I went on holiday

@ondrejmirtes
Copy link
Member

Hi, the logic in the extension is solid but:

  1. I don't get the change in composer.json.
  2. The build failed.

@ruudk
Copy link
Contributor

ruudk commented Oct 21, 2020

@raalderink Are you going to fix this or should I take it over?

@ruudk
Copy link
Contributor

ruudk commented Oct 21, 2020

@ondrejmirtes @raalderink Let's continue in #107 which is ✅ and ready to merge 🎉

@raalderink raalderink deleted the fix-input-bag-synamic-return-type branch October 22, 2020 06:58
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.

3 participants