GithubHelp home page GithubHelp logo

Comments (5)

szepeviktor avatar szepeviktor commented on July 23, 2024 1

core-stubs.php

<?php

function apple(): void
{
    echo 'Apple is a fruit';
}

app.php

<?php

if (! function_exists('apple')) :

function apple(): void
{
    echo 'Apple is a juicy fruit';
}

endif;

phpstan analyse -a core-stubs.php -l max app.php


 [OK] No errors

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 23, 2024

Thank you again for your suggestion.

is wrapped in an if ( ! function_exists ) block. The stubs for these should ideally be treated the same

Just wrap your functions overriding core functions in function_exists.

from wordpress-stubs.

mallardduck avatar mallardduck commented on July 23, 2024

While that was one option I considered, I ruled this out as my implementation is maintained by me I'd rather mine be analysed in my project by PHPStan than use the stub implementation.

From the looks of it, this repo uses another one of @GiacoCorsiglia to generate the stubs and I'd guess this underlying library doesn't account for the functions that wp-core if wraps. So if they're active or around then maybe I could help fix that upstream.
However per your other comments though it seems they may not be as active to accept the PR?

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on July 23, 2024

I'd rather mine be analysed in my project by PHPStan than use the stub implementation.

Actually PHPStan does analyze your code.

Changing app.php to

<?php

if (! function_exists('apple')) :

function apple(): void
{
    echo 'Apple is a juicy fruit';
    return $horribleError;
}

endif;

produces 2 errors

 ------ --------------------------------------------------------------------------------------
  Line   app.php
 ------ --------------------------------------------------------------------------------------
  8      Function apple() with return type void returns mixed but should not return anything.
  8      Undefined variable: $horribleError
 ------ --------------------------------------------------------------------------------------

from wordpress-stubs.

mallardduck avatar mallardduck commented on July 23, 2024

Sorry - I may be a bit confused about PHPStan's inner workings, or poorly explained my thought/concern.

My thought was that the areas of my code/wp-core that utilize said function would analyze it differently if it associated it with the stub vs with my implementation.

However now that I write that out I realize that's an assumption I've made about how PHPStan connects/associates different areas of code during analysis.

from wordpress-stubs.

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.