GithubHelp home page GithubHelp logo

johnbillion / args Goto Github PK

View Code? Open in Web Editor NEW
107.0 6.0 6.0 519 KB

Array arguments made bearable

Home Page: https://packagist.org/packages/johnbillion/args

License: GNU General Public License v2.0

PHP 100.00%
wordpress phpstan strict-types

args's Introduction

args's People

Contributors

johnbillion avatar lipemat avatar ocean90 avatar proweb avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

args's Issues

Redundant type hints

	/**
	 * The number of posts to query for. Use -1 to request all posts.
	 *
	 * @var int
	 */
	public int $posts_per_page;

How about telling its type only once?

	/**
	 * The number of posts to query for. Use -1 to request all posts.
	 */
	public int $posts_per_page;

passing an `Args` instance to `WP_Query` without `toArray()` silently yields subtle bugs

I spent the past few hours trying to figure out why two nearly-identical queries in my project yielded wildly different results. Both used the same tax_query->clauses, but only one of the resulting queries actually respected the clause. It turns out that I had forgotten to call toArray() on the instance of \Args\WP_Query prior to passing it to the \WP_Query constructor. I would have expected that to cause an obvious error.

The query with new WP_Query($args->toArray()) correctly filtered posts by tax_query, while the query with new WP_Query($args) did not respect tax_query but also did not fail entirely.

PHP 8.1: PHP Deprecated: Return type of Args\Shared\Base::offsetGet($offset)

PHP deprecation notice when running PHP 8.1.

PHP Deprecated:  Return type of Args\Shared\Base::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/wordpress/vendor/johnbillion/args/src/Shared/Base.php on line 47
  • Tested w/ johnbillion/args (1.3.0 => 1.4.0)
  • WordPress 6.0
  • PHP 8.1

Test generate.php

PHPStan would approve generate.php with this diff.

diff --git a/generate.php b/generate.php
index e23d303..ff34d23 100644
--- a/generate.php
+++ b/generate.php
@@ -7,6 +7,7 @@ use phpDocumentor\Reflection\Php\Project;

 require_once __DIR__ . '/vendor/autoload.php';

+/** @var array{"file"?:string, "method"?:string, "function"?:string, "param"?:string} $options */
 $options = getopt( '', [
        'file:',
        'method::',
@@ -79,6 +80,7 @@ if ( ! empty( $options['method'] ) ) {
        $symbol = $methods[ $options['method'] ];
        $name = $oc;
 } else {
+       /** @var array{"file":string, "function":string, "param":string} $options */
        $functions = $file->getFunctions();

        if ( ! isset( $functions[ $options['function'] ] ) ) {
@@ -93,9 +95,9 @@ if ( ! empty( $options['method'] ) ) {
        $name = trim( $options['function'], '()' );
 }

+/** @var BaseTag[] $tags */
 $tags = $symbol->getDocBlock()->getTags();

-/** @var BaseTag[] $tags */
 $tags = array_values( array_filter( $tags, function( BaseTag $tag ) : bool {
        return ( $tag instanceof Param );
 } ) );

Reduce number of exported files

How about not exporting these files?

CONTRIBUTING.md

phpcs.xml.dist
phpstan.neon.dist
phpunit.xml.dist

generate.php
shape.php
shapes.php

Current state:

kรฉp

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.