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

Update ComponentModel\Container stub for component-model 3.1.0 #142

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from

Conversation

jtojnar
Copy link

@jtojnar jtojnar commented May 18, 2024

That version changes the return type to array when $deep argument is false (default):
nette/component-model@7f613ee

It also deprecates the arguments but we cannot add deprecated annotation to those.
nette/component-model@4e0946a

@jtojnar jtojnar force-pushed the cm-container-3.1 branch 2 times, most recently from ed45fb8 to 11e9969 Compare May 18, 2024 12:18
@jtojnar
Copy link
Author

jtojnar commented May 18, 2024

It also deprecates the arguments but we cannot add deprecated annotation to those.

There is no @param-deprecated annotation AFAICT and the upcoming #[Deprecated] attribute RFC leaves it up for future.

@jtojnar jtojnar marked this pull request as draft May 18, 2024 12:22
@jtojnar jtojnar force-pushed the cm-container-3.1 branch from 11e9969 to 4a7f493 Compare May 18, 2024 12:24
@jtojnar
Copy link
Author

jtojnar commented May 18, 2024

Looks like this is recognized properly, as I no longer get

  173    Parameter #1 $array of function array_filter expects array, Iterator<int|string, Nette\ComponentModel\IComponent> given.  

But for some reason it now thinks it returns the union of both branches:

  173    Parameter #1 $array of function array_filter expects array, array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> given.  

(This is with PHPStan 1.11.1.)

@jtojnar jtojnar force-pushed the cm-container-3.1 branch from 4a7f493 to 5113331 Compare May 18, 2024 12:34
@jtojnar
Copy link
Author

jtojnar commented May 18, 2024

I tried to reproduce it in Playground but it does not fail there: https://phpstan.org/r/50c723fc-6a84-4ca3-945d-fdc4fc5f9fbc

Possibly this is some difference in how stubs are handled?

@jtojnar jtojnar changed the base branch from 1.1.x to 2.0.x January 11, 2025 10:49
@jtojnar jtojnar marked this pull request as ready for review January 11, 2025 10:55
@jtojnar
Copy link
Author

jtojnar commented Jan 14, 2025

Okay, added tests, which reproduce the issue when I force the nette/component-model to 3.1.0 – for some reason the returned type is union of the both branches of the ternary expression in the @return.

1) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:16" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Compo...onent>', 'array<int|string, Nette\Compo...onent>', 16)
Expected type array<int|string, Nette\ComponentModel\IComponent>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 16.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\ComponentModel\IComponent>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'

phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35

2) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:17" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Forms...ainer>', 'array<int|string, Nette\Compo...onent>', 17)
Expected type array<int|string, Nette\Forms\Container>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 17.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\Forms\Container>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'

phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35

3) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:18" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'Iterator<int|string, Nette\Co...onent>', 'array<int|string, Nette\Compo...onent>', 18)
Expected type Iterator<int|string, Nette\ComponentModel\IComponent>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 18.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Iterator<int|string, Nette\ComponentModel\IComponent>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'

phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35

4) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:19" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'Iterator<int|string, Nette\Fo...ainer>', 'array<int|string, Nette\Compo...onent>', 19)
Expected type Iterator<int|string, Nette\Forms\Container>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 19.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Iterator<int|string, Nette\Forms\Container>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'

phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35

5) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:20" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Compo...onent>', 'mixed', 20)
Expected type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>, got type mixed in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 20.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
+'mixed'

phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35

And it seems to work just fine in the playground:

https://phpstan.org/r/d65ff1c0-3cf4-4cda-ab15-792478c7ce34

@jtojnar jtojnar force-pushed the cm-container-3.1 branch 2 times, most recently from 3b24c68 to 44ed7d8 Compare January 14, 2025 09:03
That version changes the return type to array when `$deep` argument is `false` (default):
nette/component-model@7f613ee

It also deprecates the arguments but we cannot add deprecated annotation to those.
nette/component-model@4e0946a
@jtojnar
Copy link
Author

jtojnar commented Jan 14, 2025

Also note that the CI currently does not test component-model 3.1.0 due to package and PHP version conflicts. I had to force it locally:


--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,8 @@
 		"MIT"
 	],
 	"require": {
-		"php": "^7.4 || ^8.0",
+		"php": " ^8.0",
+		"nette/component-model": "3.1.0",
 		"phpstan/phpstan": "^2.0"
 	},
 	"conflict": {
@@ -21,7 +22,7 @@
 		"nette/application": "^3.0",
 		"nette/di": "^3.1.10",
 		"nette/forms": "^3.0",
-		"nette/utils": "^2.3.0 || ^3.0.0",
+		"nette/utils": "^2.3.0 || ^3.0.0 || ^4.0.0",
 		"php-parallel-lint/php-parallel-lint": "^1.2",
 		"phpstan/phpstan-phpunit": "^2.0",
 		"phpstan/phpstan-strict-rules": "^2.0",
@@ -29,7 +30,6 @@
 	},
 	"config": {
 		"platform": {
-			"php": "7.4.6"
 		},
 		"sort-packages": true
 	},

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.

1 participant