Giter VIP home page Giter VIP logo

assets's People

Contributors

gmazzap 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

Watchers

 avatar  avatar  avatar  avatar

assets's Issues

Dequeue ability

Nice code - not joking when I say it reduced my asset enqeueuing code by >50% and made it far more readable :D

For completeness though, it'd be nice to have a simple method for dequeuing an arbitrary asset. As an example, my theme spits out its own styles for a particular plugin, making the plugin styles useless. It'd be great to be able to dequeue the plugin styles through the class (for literally no other reason than pretty code)

$assets = Assets::forTheme();

$manifest = $assets
            ->enqueueScript('manifest', ['jquery'])
            ->useDefer()

$vendor = $assets
            ->enqueueScript('vendor', [$manifest])
            ->useDefer();

$app = $assets
            ->enqueueScript('vendor', [$vendor])
            ->useDefer();

// ew...
wp_dequeue_script('some-plugin-script');

// wow! :D
$assets->dequeue('some-plugin-script')

Static analyzers

Hello @gmazzap !

Very nice code. Psalm helps you keep code quality high.

Some things to consider

  • use phpstan-wordpress, you don't have to write core functions stubs yourself!
  • @phpstan is a better tool
  • near-zero configuration
  • try avoiding casting values $baseUrl = (string)$context->baseUrl();
  • convert closures to proper methods
  • figure out null default values

All the best to you!

diff --git a/composer.json b/composer.json
index e8db817..a5f08e2 100644
--- a/composer.json
+++ b/composer.json
@@ -29,7 +29,8 @@
         "brain/monkey": "^2",
         "squizlabs/php_codesniffer": "3.2.*",
         "inpsyde/php-coding-standards": "0.*",
-        "vimeo/psalm": "^3"
+        "phpstan/phpstan-shim": "^0.11.8",
+        "szepeviktor/phpstan-wordpress": "^0.1.2"
     },
     "scripts": {
         "qa": [
diff --git a/src/Assets.php b/src/Assets.php
index d216df9..f8c8d88 100644
--- a/src/Assets.php
+++ b/src/Assets.php
@@ -810,7 +810,9 @@ class Assets
      */
     private function tryRelativeUrl(string $url, string $folder, ?string $baseUrl = null): string
     {
+        /** @var string[] */
         $urlData = parse_url($url);
+        /** @var string[] */
         $baseData = parse_url($baseUrl ?? $this->context->baseUrl());

         $urlHost = (string)($urlData['host'] ?? '');
diff --git a/src/UrlResolver/DirectUrlResolver.php b/src/UrlResolver/DirectUrlResolver.php
index 9275d2f..883d217 100644
--- a/src/UrlResolver/DirectUrlResolver.php
+++ b/src/UrlResolver/DirectUrlResolver.php
@@ -29,6 +29,7 @@ final class DirectUrlResolver implements UrlResolver
         $baseUrl = $this->context->baseUrl();
         $basePath = $this->context->basePath();

+        /** @var string[] */
         $urlData = parse_url($relative);
         $path = trim((string)($urlData['path'] ?? ''), '/');
         $query = (string)($urlData['query'] ?? '');
diff --git a/src/Version/LastModifiedVersion.php b/src/Version/LastModifiedVersion.php
index 564fe9b..b2e1e43 100644
--- a/src/Version/LastModifiedVersion.php
+++ b/src/Version/LastModifiedVersion.php
@@ -7,7 +7,7 @@ use Brain\Assets\Context\Context;
 final class LastModifiedVersion implements Version
 {
     /**
-     * @var array<string, array{0:string, 1:int}>
+     * @var array<string, array>
      */
     private $bases = [];

phpstan.neon.dist

# Start command: vendor/bin/phpstan analyze

includes:
    - phar://phpstan.phar/conf/bleedingEdge.neon
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
    level: max
    paths:
        - %currentWorkingDirectory%/src/
    ignoreErrors:
        # Uses func_get_args()
        - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#'

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.