Skip to content

Commit

Permalink
Code Style
Browse files Browse the repository at this point in the history
  • Loading branch information
inpsyde-maticluznar committed Jul 23, 2024
1 parent ec47757 commit 891e9ab
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Assets
type: wordpress
docroot: .ddev/wordpress
php_version: "8.2"
php_version: "8.0"
webserver_type: apache-fpm
xdebug_enabled: false
additional_hostnames: []
Expand Down
40 changes: 18 additions & 22 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ private function ensureSetup(): void
do_action(self::ACTION_SETUP, $this);
}

public function ignoreCache(){
public function ignoreCache()

Check failure on line 327 in src/AssetManager.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-php / static-analysis-php

MissingReturnType

src/AssetManager.php:327:21: MissingReturnType: Method Inpsyde\Assets\AssetManager::ignoreCache does not have a return type, expecting void (see https://psalm.dev/050)
{

$this->ignoreCacheHandler->execute($this);
}
}
29 changes: 10 additions & 19 deletions src/Caching/IgnoreCacheHandler.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@
<?php

/*
* This file is part of the Assets package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace Inpsyde\Assets\Caching;


use Inpsyde\Assets\Asset;
use Inpsyde\Assets\AssetManager;
use Inpsyde\Assets\BaseAsset;
use Inpsyde\Assets\Script;
use Inpsyde\Assets\Style;

class IgnoreCacheHandler{
class IgnoreCacheHandler
{
public function execute(AssetManager $assetManager)

Check failure on line 13 in src/Caching/IgnoreCacheHandler.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-php / static-analysis-php

MissingReturnType

src/Caching/IgnoreCacheHandler.php:13:21: MissingReturnType: Method Inpsyde\Assets\Caching\IgnoreCacheHandler::execute does not have a return type, expecting void (see https://psalm.dev/050)
{
/** @var IgnorePluginCacheInterface[] $handlers */
$handlers = [
new IgnoreW3TotalCache(),
new IgnoreSitegroundCache()
new IgnoreSitegroundCache(),
];

$assets = $assetManager->assets();

$assetHandles = [
Script::class => [],
Style::class => []
Style::class => [],
];

foreach($assets as $assetKey => $assetType){
foreach($assetType as $asset){
foreach ($assets as $assetKey => $assetType) {
foreach ($assetType as $asset) {
$assetHandles[$assetKey][] = $asset->handle();
}
}

foreach($handlers as $ignorePluginHandler){
if($ignorePluginHandler->isInstalled()){
foreach ($handlers as $ignorePluginHandler) {
if ($ignorePluginHandler->isInstalled()) {
$ignorePluginHandler->apply($assetHandles);
}
}
}
}
}
16 changes: 4 additions & 12 deletions src/Caching/IgnorePluginCacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?php

/*
* This file is part of the Assets package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace Inpsyde\Assets\Caching;

use Inpsyde\Assets\Asset;

interface IgnorePluginCacheInterface{
interface IgnorePluginCacheInterface
{
public function isInstalled(): bool;
public function apply(array $handles): void;
}
}
26 changes: 11 additions & 15 deletions src/Caching/IgnoreSitegroundCache.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?php

/*
* This file is part of the Assets package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace Inpsyde\Assets\Caching;

Expand All @@ -30,22 +23,25 @@ public function apply(array $handles): void
/**
* Ignore Javascript
*/
add_filter('sgo_js_minify_exclude', function (array $scripts) use($handles) {
add_filter('sgo_js_minify_exclude', static function (array $scripts) use ($handles) {
return array_merge($scripts, $handles[Script::class]);
});

add_filter('sgo_javascript_combine_exclude', function (array $scripts) use($handles){
return array_merge($scripts, $handles[Script::class]);
});
add_filter(
'sgo_javascript_combine_exclude',
static function (array $scripts) use ($handles) {
return array_merge($scripts, $handles[Script::class]);
}
);

/**
* Ignore Styles
*/
add_filter('sgo_css_minify_exclude', function (array $styles) use($handles){
add_filter('sgo_css_minify_exclude', static function (array $styles) use ($handles) {
return array_merge($styles, $handles[Style::class]);
});
add_filter('sgo_css_combine_exclude', function (array $styles) use($handles){
add_filter('sgo_css_combine_exclude', static function (array $styles) use ($handles) {
return array_merge($styles, $handles[Style::class]);
});
}
}
}
25 changes: 10 additions & 15 deletions src/Caching/IgnoreW3TotalCache.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?php

/*
* This file is part of the Assets package.
*
* (c) Inpsyde GmbH
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);

namespace Inpsyde\Assets\Caching;

Expand All @@ -25,14 +18,16 @@ public function isInstalled(): bool
return class_exists('W3TC\Root_Loader');
}

// phpcs:disable Inpsyde.CodeQuality.NestingLevel.High

public function apply(array $handles): void
{
/**
* Ignore Javascript
*/
add_filter('w3tc_minify_js_do_tag_minification', function(bool $doMinification, string $scriptTag) use($handles){
foreach($handles[Script::class] as $handle){
if(strpos( $scriptTag, $handle ) !== false){
add_filter('w3tc_minify_js_do_tag_minification', static function (bool $doMinification, string $scriptTag) use ($handles) {
foreach ($handles[Script::class] as $handle) {
if (strpos($scriptTag, $handle) !== false) {
return false;
}
}
Expand All @@ -42,13 +37,13 @@ public function apply(array $handles): void
/**
* Ignore Styles
*/
add_filter('w3tc_minify_css_do_tag_minification', function(bool $doMinification, string $scriptTag) use($handles){
foreach($handles[Style::class] as $handle){
if(strpos( $scriptTag, $handle ) !== false){
add_filter('w3tc_minify_css_do_tag_minification', static function (bool $doMinification, string $scriptTag) use ($handles) {
foreach ($handles[Style::class] as $handle) {
if (strpos($scriptTag, $handle) !== false) {
return false;
}
}
return $doMinification;
}, 10, 2);
}
}
}

0 comments on commit 891e9ab

Please sign in to comment.