Giter Site home page Giter Site logo

Comments (5)

ondrejmirtes avatar ondrejmirtes commented on May 8, 2024 1

Hi, this works exactly as it's supposed to. When PHP does not allow you to define the precise property type via native types, you need to add a PHPDoc.

The correct way to typehint this is MockInterface&Foo, see the differences between union types and intersection types: https://phpstan.org/blog/union-types-vs-intersection-types

There's a hardcoded exception so that MockInterface|Foo is also interpreted as an intersection type because that's what people mean when they write that.

I don't plan to infer the assigned type from the setUp() method, that's not what the extensions support.

from phpstan-mockery.

ruudk avatar ruudk commented on May 8, 2024

Thanks for the explanation.

There's a hardcoded exception so that MockInterface|Foo is also interpreted as an intersection type because that's what people mean when they write that.

Btw, I was aware of the intersection typing. Somehow people keep on adding the union types in our codebase. Would it be possible to make this configurable? So that you can only use intersect? (willing to create the PR if you agree).

from phpstan-mockery.

ondrejmirtes avatar ondrejmirtes commented on May 8, 2024

Would it be possible to make this configurable?

Yes, it's easy.

  1. Create a new bool parameter for this.
  2. Remove the tag from this service definiton:
    -
    class: PHPStan\Mockery\PhpDoc\TypeNodeResolverExtension
    tags:
    - phpstan.phpDoc.typeNodeResolverExtension
  3. Create a new conditionalTags section like here: https://github.com/phpstan/phpstan-src/blob/6f7cadf96c7b55a0df21b51730e4b53ad13a7545/conf/config.level4.neon#L20-L30

from phpstan-mockery.

ruudk avatar ruudk commented on May 8, 2024

@ondrejmirtes Like this #28 :D ?

from phpstan-mockery.

github-actions avatar github-actions commented on May 8, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from phpstan-mockery.

Related Issues (19)

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.