Git Product home page Git Product logo

Comments (3)

tsufeki avatar tsufeki commented on May 27, 2024 1

I relaxed the logic for union types in completions, go to, hovers etc . (03be2af), they should work as you expect.

But reponse()->json() will still be underlined as a warning - it'll be fixed when I integrate laravel extension (hopefully soon).

Thanks.

from tenkawa-php-language-server.

tsufeki avatar tsufeki commented on May 27, 2024

That's how union type A|B work: language server does not know if $x is actually A or actually B. Since method is only on A, it is ignored as it may be inaccessible. You need an explicit check:

/**
 * @var A|B
 */
$x = ...
if ($x instanceof A) {
    $x->test();
}

For A&B, an object can't be an instance of two unrelated classes at the same time so this type is an error. However, if B was an interface it would work:

<?php
class A
{
    public function test()
    {
    }
}

interface B
{
}

/**
 * @var A&B
 */
$x = ...
$x->test();

Tenkawa is very strict about this. I guess it could make sense to relax this behaviour a bit, but I need give it some more thought.

Anyway, thank you for reporting this. If you find any more issues, feel free to report them as well.

btw I can recommend an article Union Types vs. Intersection Types

from tenkawa-php-language-server.

xiaohuilam avatar xiaohuilam commented on May 27, 2024

Usually, Go to definition code was presented in vendor, which not override-able by this project owner.
For example, the laravel framework's response() helper method, it defines to return @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory, and like i example upon this comment, the class before | does not contain json method, but after one does, when i write reponse()->json(), i think i shouldn't to check it like this:

$response = response();
if ($response instanceof \Illuminate\Contracts\Routing\ResponseFactory) {
    return $response->json(['success' => true]);
}

from tenkawa-php-language-server.

Related Issues (14)

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.