-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Declare more precise phpdoc types #993
Conversation
lib/PhpParser/Node/Name.php
Outdated
@@ -8,6 +8,7 @@ class Name extends NodeAbstract | |||
{ | |||
/** | |||
* @var string[] Parts of the name | |||
* @psalm-var non-empty-array<string> | |||
* @deprecated Use getParts() instead | |||
*/ | |||
public $parts; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could even declare * @param non-empty-string|non-empty-array<string>|self $name
in __construct
but since more strict param types could be considered a BC break, I did not add this change.
in the same turn I think about making the |
Can you please target this at master instead?
I think that's fine. Empty string identifiers need to be written as something like |
the CI build on php-parser@v5 looks pretty broken. it seems there is some chicken-egg problem regarding deps and v4. |
after a deep dive into the CI problem I found a solution (its still not caused by this PR though). the last remaining question is #993 (comment) Thank you. |
I’m not a huge fan of this. More precise parameter types will break static analysis in many projects, forcing people to write more precise PHPDoc types. These types of changes should be done only in a major version IMHO. |
Yeah thats why I asked. I am fine with return type improvements only |
Yeah, return types should be fine, although it's a slight BC break too. Imagine you're extending a class and typehinting string return type. If the parent narrows the return type, suddenly the child return type is no longer covariant. |
@@ -20,7 +20,7 @@ jobs: | |||
- name: "Install dependencies" | |||
run: | | |||
composer require php-coveralls/php-coveralls:^2.2 --dev --no-update | |||
composer update --no-progress --prefer-dist | |||
COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do / why is it necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this fix, CI errors in PRs of forks. see #993 (comment)
errors beeing fixed can be seen here: https://github.com/nikic/PHP-Parser/actions/runs/8671744331/job/23781260607?pr=993
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- phpunit/phpunit[9.6.12, ..., 9.6.19] require phpunit/php-code-coverage ^9.2.28 -> satisfiable by phpunit/php-code-coverage[9.2.28, 9.2.29, 9.2.30, 9.2.31].
- phpunit/phpunit[9.5.16, ..., 9.6.11] require phpunit/php-code-coverage ^9.2.13 -> satisfiable by phpunit/php-code-coverage[9.2.13, ..., 9.2.31].
- phpunit/phpunit[9.5.10, ..., 9.5.14] require phpunit/php-code-coverage ^9.2.7 -> satisfiable by phpunit/php-code-coverage[9.2.7, ..., 9.2.31].
- phpunit/phpunit[9.5.0, ..., 9.5.9] require phpunit/php-code-coverage ^9.2.3 -> satisfiable by phpunit/php-code-coverage[9.2.3, ..., 9.2.31].
- phpunit/phpunit[9.4.0, ..., 9.4.4] require phpunit/php-code-coverage ^9.2 -> satisfiable by phpunit/php-code-coverage[9.2.0, ..., 9.2.31].
- phpunit/phpunit 9.3.11 requires phpunit/php-code-coverage ^9.1.11 -> satisfiable by phpunit/php-code-coverage[9.1.11, ..., 9.2.31].
- phpunit/phpunit[9.3.8, ..., 9.3.10] require phpunit/php-code-coverage ^9.1.5 -> satisfiable by phpunit/php-code-coverage[9.1.5, ..., 9.2.31].
- phpunit/phpunit[9.3.4, ..., 9.3.7] require phpunit/php-code-coverage ^9.1.1 -> satisfiable by phpunit/php-code-coverage[9.1.1, ..., 9.2.31].
- phpunit/phpunit[9.3.0, ..., 9.3.3] require phpunit/php-code-coverage ^9.0 -> satisfiable by phpunit/php-code-coverage[9.0.0, ..., 9.2.31].
- phpunit/phpunit[9.0.0, ..., 9.2.6] require php ^7.3 -> your php version (8.3.6) does not satisfy that requirement.
- phpunit/php-code-coverage[9.0.0, ..., 9.1.2] require nikic/php-parser ^4.7 -> satisfiable by nikic/php-parser[v4.7.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.1.3, ..., 9.2.2] require nikic/php-parser ^4.8 -> satisfiable by nikic/php-parser[v4.8.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.2.3, ..., 9.2.6] require nikic/php-parser ^4.10.2 -> satisfiable by nikic/php-parser[v4.10.2, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage 9.2.7 requires nikic/php-parser ^4.12.0 -> satisfiable by nikic/php-parser[v4.12.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.2.8, ..., 9.2.15] require nikic/php-parser ^4.13.0 -> satisfiable by nikic/php-parser[v4.13.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.2.16, ..., 9.2.24] require nikic/php-parser ^4.14 -> satisfiable by nikic/php-parser[v4.14.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.2.25, ..., 9.2.29] require nikic/php-parser ^4.15 -> satisfiable by nikic/php-parser[v4.15.0, ..., 4.x-dev] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- phpunit/php-code-coverage[9.2.30, ..., 9.2.31] require nikic/php-parser ^4.18 || ^5.0 -> satisfiable by nikic/php-parser[dev-master, v4.18.0, v4.19.0, v4.19.1, 4.x-dev, v5.0.0alpha1, ..., 5.0.x-dev (alias of dev-master)] from composer repo (https://repo.packagist.org/) but nikic/php-parser is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- Root composer.json requires phpunit/phpunit ^9.0 -> satisfiable by phpunit/phpunit[9.0.0, ..., 9.6.19].
Error: Your requirements could not be resolved to an installable set of packages.
without thix fix composer does not realize what the version of the package of the checked-out project is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I guess I caused this with b43758e and previously this probably just resolved to PHPUnit 8 instead...
@@ -25,6 +28,10 @@ class Identifier extends NodeAbstract { | |||
* @param array<string, mixed> $attributes Additional attributes | |||
*/ | |||
public function __construct(string $name, array $attributes = []) { | |||
if ($name === '') { | |||
throw new \InvalidArgumentException('Identifier name cannot be empty'); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goal: ease working in projects which are static analysis covered.
we are doing the same thing in PHPStan with phpstan/phpstan-src#3013 (review)