Bump to PHP 7.4+ and upgrade to PHPStan v2#639
Bump to PHP 7.4+ and upgrade to PHPStan v2#639MarcelloDuarte merged 5 commits intophpspec:masterfrom
Conversation
| message: '#^Parameter \#1 \$value of function strval expects bool\|float\|int\|resource\|string\|null, mixed given\.$#' | ||
| identifier: argument.type |
There was a problem hiding this comment.
Multiple lines here are changed just because PHPStan v2 does no longer double-escape, and adds the identifier of the error. I'll comment only on new ignored issues.
| - | ||
| message: '#^Method Prophecy\\Doubler\\CachedDoubler\:\:createDoubleClass\(\) should return class\-string\<Prophecy\\Doubler\\DoubleInterface&T of object\> but returns class\-string\.$#' | ||
| identifier: return.type |
There was a problem hiding this comment.
This is a method extending its parent which is generic. It seems that the nested-double generic isn't working, we could report this upstream to PHPStan
| message: '#^Call to function method_exists\(\) with ''ReflectionClass'' and ''isReadOnly'' will always evaluate to true\.$#' | ||
| identifier: function.alreadyNarrowedType | ||
| count: 1 | ||
| path: src/Prophecy/Doubler/Generator/ClassMirror.php | ||
|
|
||
| - | ||
| message: '#^Call to function method_exists\(\) with ReflectionMethod and ''hasTentativeReturnT…'' will always evaluate to true\.$#' | ||
| identifier: function.alreadyNarrowedType | ||
| count: 1 | ||
| path: src/Prophecy/Doubler/Generator/ClassMirror.php |
There was a problem hiding this comment.
These two are due to the fact that those reflection methods are present only from PHP 8.1. These workaround go away as soon as we bump the minimum PHP version.
phpstan-baseline.neon
Outdated
| message: '#^PHPDoc tag @var with type static\(Prophecy\\Doubler\\LazyDouble\<U of object\>\) is not subtype of native type \$this\(Prophecy\\Doubler\\LazyDouble\<T of object\>\)\.$#' | ||
| identifier: varTag.nativeType | ||
| count: 1 | ||
| path: src/Prophecy/Doubler/LazyDouble.php | ||
|
|
||
| - | ||
| message: '#^Property Prophecy\\Doubler\\LazyDouble\:\:\$class \(ReflectionClass\<T of object\>\|null\) does not accept ReflectionClass\<U of object\>\.$#' | ||
| identifier: assign.propertyType | ||
| count: 1 | ||
| path: src/Prophecy/Doubler/LazyDouble.php | ||
|
|
||
| - | ||
| message: '#^Property Prophecy\\Doubler\\LazyDouble\:\:\$class \(ReflectionClass\<T of object\>\|null\) is never assigned ReflectionClass\<T of object\> so it can be removed from the property type\.$#' | ||
| identifier: property.unusedType | ||
| count: 1 | ||
| path: src/Prophecy/Doubler/LazyDouble.php |
There was a problem hiding this comment.
These 3 are all from the same issue, the setParentClass method is very hard to map against PHPStan because it changes the type of the generic of the instance itself.
| - | ||
| message: '#^Call to function method_exists\(\) with ReflectionMethod and ''hasTentativeReturnT…'' will always evaluate to true\.$#' | ||
| identifier: function.alreadyNarrowedType | ||
| count: 1 | ||
| path: src/Prophecy/Prophecy/MethodProphecy.php |
There was a problem hiding this comment.
Again, 8.1+ reflection feature...
| * @param MethodProphecy $methodProphecy | ||
| * @param int $count | ||
| * @param list<Call> $calls | ||
| * @param array<Call> $calls |
There was a problem hiding this comment.
Inputing any array, casting to list below
There was a problem hiding this comment.
do we need this, or should we use a more precise type in our CallCenter (which is probably already using lists) ?
| * @param array<Call> $calls | ||
| */ | ||
| public function __construct($message, MethodProphecy $methodProphecy, array $calls) | ||
| { | ||
| parent::__construct($message, $methodProphecy); | ||
|
|
||
| $this->calls = $calls; | ||
| $this->calls = array_values($calls); |
There was a problem hiding this comment.
Same here, casting to list (previous was extending class)
| $callback = $this->callback; | ||
|
|
||
| if ($callback instanceof Closure && method_exists('Closure', 'bind') && (new ReflectionFunction($callback))->getClosureThis() !== null) { | ||
| if ($callback instanceof Closure && (new ReflectionFunction($callback))->getClosureThis() !== null) { |
There was a problem hiding this comment.
bind is present since PHP 5.4, we can ditch this check.
| $callback = $this->callback; | ||
|
|
||
| if ($callback instanceof Closure && method_exists('Closure', 'bind') && (new ReflectionFunction($callback))->getClosureThis() !== null) { | ||
| if ($callback instanceof Closure && (new ReflectionFunction($callback))->getClosureThis() !== null) { |
There was a problem hiding this comment.
bind is present since PHP 5.4, we can ditch this check.
|
|
||
| $values = "\n".$values.$whitespace; | ||
| } | ||
| \assert(\is_object($value)); |
There was a problem hiding this comment.
This is just a change in how PHPStan detect types; better but not completely.
|
@MarcelloDuarte I've bumped to PHP 7.4 as discussed. I've also fixed the PHPStan analysis, but I saw that the output depends on the PHP version it runs on. It seems acceptable for now. I also added a changelog entry, so that a 1.22 should be released with this bump. Let me know if this is ok or if it needs more work. |
| } | ||
|
|
||
| return $types; | ||
| return array_values($types); |
There was a problem hiding this comment.
this is actually an issue in phpstan IMO. It should know that ReflectionUnionType::getTypes returns a list (so that doing array_map on it still returns a list)
| return 'Array &'.$key; | ||
| } | ||
|
|
||
| \assert(\is_array($value)); |
There was a problem hiding this comment.
isn't this removal causing the issues reported just below ?
There was a problem hiding this comment.
how is this PR unblocking phpspec ? Removing support for PHP versions in a dependency cannot be a blocker (phpspec requires that prophecy supports at least all the PHP versions it needs, but does not care if it supports more).
There was a problem hiding this comment.
It's some sort of circular dependency around stan. That wasn't my question though... Is this mergeable? Do we need to keep supporting PHP versions in EOL state to keep the next tag within minor release?
There was a problem hiding this comment.
Do we need to keep supporting PHP versions in EOL state to keep the next tag within minor release?
As long as we update our php requirement properly in the composer.json, dropping support for some PHP versions is not a BC break (as composer will still respect that requirement when resolving semver ranges). That's still something that deserves a minor version IMO (it is not a bugfix), but it does not require a major version bump as far as Composer is concerned (Symfony itself has a policy to be stricter for the fullstack framework, but that's for other reasons)
@MarcelloDuarte this is the PR that I promised. I'll self-review to add more context to each change.