Git Product home page Git Product logo

Comments (5)

nikophil avatar nikophil commented on August 27, 2024 1

Hey @norkunas

thank you for this report.

but that's just nonsense to add this to 100+ factories

you're absolutely right, we're gonna find a solution!

After some times scratching my head looking for an explanation, I think I've found the problem:
https://phpstan.org/r/a7f5de6f-afaf-4972-8d51-a6932bfd9cc8

It seems that PHPStan "lose" the inherited array definition if the return type is changed 🤷
so I think that it thinks the prototype of the method is array<array-key, mixed> which is not covariant with array<string, mixed>

I think as an easy fix, you could replace all return types from array to array|callable. Would you try and tell me if it works for you?

I've asked on PHPStan's GitHub if this is a bug or a feature 😅 and we'll see what to do... (maybe the solution would be to modify this return type with rector rules)

from foundry.

norkunas avatar norkunas commented on August 27, 2024 1

Yup, max level/bleeding edge :)

I think we're stuck for now and I hate this 😬

I just added everywhere @return array<string, mixed> for now, so no rush :)

from foundry.

nikophil avatar nikophil commented on August 27, 2024

ok so this is a bug in PHPStan... I think the simplest solution is to add return type array|callable everywhere.
I'll add a rector rule for this

from foundry.

norkunas avatar norkunas commented on August 27, 2024

But then if you don't return a callable, phpstan complains also and says to narrow type, this is included in issue description :)

from foundry.

nikophil avatar nikophil commented on August 27, 2024

wow sorry, I haven't seen that

big 🤦 here

that's strange it did not occurred to me... is that coming from level 9? (I'm only using level 8 on my projects)

I think we're stuck for now and I hate this 😬

I got plans to create a PHPStan extension for Foundry where we can fix this, but I don't know when I'll got enough time. (And I expect Psalm users to show up, with some related problems 🤷)

from foundry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.