Conversation
06c0768 to
d1c0675
Compare
If you want to allow passing
By including the stubs directly in your project first. |
|
I've ran this PR on top of my local branch where I do some basic stub validation. Here are the errors: |
Hmm... isn't that always the case? Can you give an example where
Thanks! This is very helpful. |
|
It's not always the case, if you're not careful you can produce a runtime error. See: /**
* @param Collection<Animal> $animalCollection
*/
function addAnimal(Collection $animalCollection): void
{
$collection->add(new Cat()); // this is fine, code does not violate anything
}
/**
* @param Collection<Dog> $dogCollection
*/
function takesDogList(Collection $dogCollection): void
{
addAnimal($dogCollection); // this is not, Cat will be added
} |
|
Ok, that explains it a bit. Though I still don't quite understand how to decide which type parameter should be covariant and which shouldn't. 🤔 |
|
I must admit I don't either. But PHPStan can usually point out if the |
|
Turns out the |
5794584 to
5946c81
Compare
|
Rebased to master but I don't know how to run the tests to see the errors you reported earlier. When I run phing I'm getting some completely unrelated issues: |
|
I fixed the errors you posted but I still don't know what to do with |
|
I added the dynamic return type extension. I tested it on my project and it seems to work fine. |
|
In my project when I put |
|
Hi, the build is failing, please fix it: https://travis-ci.org/phpstan/phpstan-src/jobs/631809338?utm_medium=notification&utm_source=github_status It's not ideal to run the build on PHP 7.4. PHPStan supports it, but Phing outputs some deprecated warnings and PHPCS is completely skipped. |
|
If PHPStan isn't reporting anything, template-covariant should be fine. |
5c273fe to
8301008
Compare
|
Coding style should be fixed now. Changed everything to |
|
Build is failing because the ds extension is missing on travis so we need to add it using |
|
The extension isn’t necessary for anything, the code doesn’t depend on it. Why does it fail? (I’m on mobile.) |
|
Here is the failure: Since it only reports the Map class, I assume it's because of the |
|
This is the issue I think: final class DsMapDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
public function getClass(): string
{
return Map::class;
}Maybe I should use |
|
Yes 😊 |
|
There are apparently some errors in the stubs. Please run vendor/bin/phing phpstan locally to see them. (It's possible it's going to be about the covariance.) |
|
Well that reported |
|
Looks awesome, thank you! We can course-correct if some problems appear in the future. |
Supercedes #24.
I noticed in existing stubs that you sometimes use
@templateand sometimes@template-covariant. Can you explain the difference to me please?How do I test this on my project now that phpstan is distributed as phar?