Giter Site home page Giter Site logo

Comments (10)

johnbillion avatar johnbillion commented on May 20, 2024 1

Potential solution for the machine-readable versus human-readable: Use @phpstan-param and @phpstan-return tags in addition to the existing @param and @return tags.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on May 20, 2024

There is room for improvement in core's source code.
That "hash-style" thing is from JavaScript. Only WordPress uses it in PHP.

This package does not alter the source code in any way, simply removes function contents.
I am open to add (rock solid) transformations!

from wordpress-stubs.

johnbillion avatar johnbillion commented on May 20, 2024

A few observations:

  • Core uses type string|array where the parameter technically also accepts a URL query string because the parameter gets passed through wp_parse_args(). I think in the context of using a tool such as PHPStan or Psalm this should be treated as array only because nobody in their right mind actually uses a query string.
  • The error message from PHPStan when an incorrect type is used is not very useful if there is a large number of array elements:

    Parameter #2 $args of method WP_Http::request() expects array(?'method' => string, ?'timeout' => float, ?'redirection' => int, ?'httpversion' => string, ?'user-agent' => string, ?'reject_unsafe_urls' => bool, ?'blocking' => bool, ?'headers' => array|string, ...), array('blocking' => WP_User) given.

from wordpress-stubs.

johnbillion avatar johnbillion commented on May 20, 2024
  • Additional array elements that are not in the documented list are allowed by PHPStan:
( new WP_Http )->request( 'http://example.com', [
	'banana' => 'yellow',
] );

[OK] No errors

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on May 20, 2024
  • Developers above 14 years should be punished for storing various data in an array
  • I'm just a single person, not capable of processing a huge codebase like WordPress

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on May 20, 2024

Developers above 14 years should be punished for storing various data in an array

PHP has object properties for more than a decade. Code could be written in a human-friendly way.

https://github.com/szepeviktor/small-project/blob/de32f4b232967f43d0d9532febc97f81ba8ec6ad/plugin-name.php#L92-L99

from wordpress-stubs.

johnbillion avatar johnbillion commented on May 20, 2024

PHP has object properties for more than a decade. Code could be written in a human-friendly way.

Oh yes I completely agree, these array-style arguments are a nightmare. I regret using them in some of my libraries such as Extended CPTs. This is why I started playing around with johnbillion/args. Unfortunately we're stuck with them in WordPress core unless we decided to implement such classes.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on May 20, 2024

Unfortunately we're stuck with them in WordPress core

Smart people started building dirt-hiding-layers between WordPress core and project-specific code - meaning what you write and read.

dirt=techdebt

from wordpress-stubs.

johnbillion avatar johnbillion commented on May 20, 2024

Alternative: Convince PHPStan and Psalm to support this hash style notation.

from wordpress-stubs.

szepeviktor avatar szepeviktor commented on May 20, 2024

Alternative: Convince PHPStan and Psalm to support this hash style notation.

WordPress marches into a dead-end. Let's convince others to join :)

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.