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

Change ConstantScalarType to Type in DisallowedCallParam #159

Merged
merged 1 commit into from Jan 6, 2023

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jan 5, 2023

This allows for more types to be matched, like a CallbackType.

In my use case, I wanted to disallow array_filter without specifying a callback.

But because the current DisallowedCallParam interface only works with ConstantScalarType this was not possible.

@ruudk ruudk force-pushed the support-callbacks-anywhere branch from b3db2af to 4b654d4 Compare January 5, 2023 08:54
This allows for more types to be matched, like a CallbackType.

In my use case, I wanted to disallow `array_filter` without specifying a callback.

But because the current `DisallowedCallParam` interface only works with `ConstantScalarType` this
was not possible.
@ruudk ruudk force-pushed the support-callbacks-anywhere branch from 4b654d4 to 84946da Compare January 5, 2023 08:56
@ruudk
Copy link
Contributor Author

ruudk commented Jan 5, 2023

@spaze Happy New Year! Please have a look when you have time!

@spaze
Copy link
Owner

spaze commented Jan 6, 2023

Happy New Year to you too @ruudk! And thanks for the PR, this makes sense 👍 I'll merge and release soon.

@spaze spaze merged commit 800f5f8 into spaze:master Jan 6, 2023
@spaze
Copy link
Owner

spaze commented Jan 6, 2023

Just released in 2.11.3, thanks again!

@ruudk
Copy link
Contributor Author

ruudk commented Jan 7, 2023

With this feature, we now also are able to detect static references like CommandBus::class in arguments. Before, those would be ignored too 😅

@spaze
Copy link
Owner

spaze commented Jan 7, 2023

Nice! Can you write a test, or more like amend an existing one, for that case? (update: #161)

@ruudk ruudk deleted the support-callbacks-anywhere branch January 9, 2023 08:10
spaze added a commit to spaze/michalspacek.cz that referenced this pull request Jan 11, 2023
This is an extra commit because things got a little complicated here.

Due to changes spaze/phpstan-disallowed-calls 2.11.3 and particularly spaze/phpstan-disallowed-calls#159, more params can be detected and PHPStan started throwing errors in spaze/sri-macros/src/Config.php:126 saying "Calling hash_file() is forbidden". The type that got passed to hash_file() was `StringType`, not `ConstantStringType` and even though the values were the ones allowed, the param was rejected.

I had to change sri-macros to pass a union of `ConstantStringType`s and phpstan-disallowed-calls to support union types.
spaze added a commit to spaze/michalspacek.cz that referenced this pull request Jan 11, 2023
This is an extra commit because things got a little complicated here.

Due to changes spaze/phpstan-disallowed-calls 2.11.3 and particularly spaze/phpstan-disallowed-calls#159, more params can be detected and PHPStan started throwing errors in spaze/sri-macros/src/Config.php:126 saying "Calling hash_file() is forbidden". The type that got passed to hash_file() was `StringType`, not `ConstantStringType` and even though the values were the ones allowed, the param was rejected.

I had to change sri-macros to pass a union of `ConstantStringType`s and phpstan-disallowed-calls to support union types.

 - spaze/phpstan-disallowed-calls updated from v2.11.2 to v2.11.3 patch
   See changes: spaze/phpstan-disallowed-calls@v2.11.2...v2.11.3
   Release notes: https://github.com/spaze/phpstan-disallowed-calls/releases/tag/v2.11.3

 - spaze/sri-macros updated from v2.0.0 to v2.0.1 patch
   See changes: spaze/sri-macros@v2.0.0...v2.0.1
   Release notes: https://github.com/spaze/sri-macros/releases/tag/v2.0.1
spaze added a commit to spaze/michalspacek.cz that referenced this pull request Jan 11, 2023
This is an extra commit because things got a little complicated here.

Due to changes spaze/phpstan-disallowed-calls 2.11.3 and particularly spaze/phpstan-disallowed-calls#159, more params can be detected and PHPStan started throwing errors in spaze/sri-macros/src/Config.php:126 saying "Calling hash_file() is forbidden". The type that got passed to hash_file() was `StringType`, not `ConstantStringType` and even though the values were the ones allowed, the param was rejected.

I had to change sri-macros to pass a union of `ConstantStringType`s and phpstan-disallowed-calls to support union types.

 - spaze/phpstan-disallowed-calls updated from v2.11.3 to v2.11.4 patch
   See changes: spaze/phpstan-disallowed-calls@v2.11.3...v2.11.4
   Release notes: https://github.com/spaze/phpstan-disallowed-calls/releases/tag/v2.11.4

 - spaze/sri-macros updated from v2.0.0 to v2.0.1 patch
   See changes: spaze/sri-macros@v2.0.0...v2.0.1
   Release notes: https://github.com/spaze/sri-macros/releases/tag/v2.0.1
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.

None yet

2 participants