Skip to content

Commit

Permalink
Merge pull request #58 from inpsyde/feature/phpcs-and-phpstan
Browse files Browse the repository at this point in the history
Feature/phpcs and phpstan
  • Loading branch information
Chrico authored Feb 27, 2025
2 parents b7de158 + 5d0479a commit e2669fa
Show file tree
Hide file tree
Showing 35 changed files with 244 additions and 215 deletions.
23 changes: 17 additions & 6 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,45 @@ jobs:
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
strategy:
matrix:
php: ["7.4", "8.0", "8.1", "8.2"]
php: [ '7.4', '8.0', '8.1', '8.2' ]
include:
- php: '7.4'
composer: '--ignore-platform-req=php'
- php: '8.0'
composer: '--ignore-platform-req=php'
with:
PHP_VERSION: ${{ matrix.php }}
COMPOSER_ARGS: ${{ matrix.composer }}
coding-standards-analysis-php:
uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main
with:
PHPCS_ARGS: '--report=summary'
PHP_VERSION: '8.0'
PHP_VERSION: '8.1'
static-code-analysis-php:
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
with:
PHP_VERSION: '8.0'
PHP_VERSION: '8.1'
tests-unit-php:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
strategy:
matrix:
php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.4', '8.0', '8.1', '8.2' ]
include:
- php: '7.4'
composer: '--ignore-platform-req=php'
- php: '8.0'
composer: '--ignore-platform-req=php'
steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ matrix.php }}

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest -a
run: composer install --prefer-dist --no-progress --no-suggest -a ${{ matrix.composer }}

- name: Run unit tests
run: composer tests:codecov
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Inpsyde Assets
# Syde Assets

[![Version](https://img.shields.io/packagist/v/inpsyde/assets.svg)](https://packagist.org/packages/inpsyde/assets)
[![Status](https://img.shields.io/badge/status-active-brightgreen.svg)](https://github.com/inpsyde/assets)
Expand All @@ -9,7 +9,7 @@


## Introduction
Inpsyde Assets is a Composer package (not a WordPress plugin) that allows to deal with scripts and styles in a WordPress site.
Syde Assets is a Composer package (not a WordPress plugin) that allows to deal with scripts and styles in a WordPress site.

## Installation

Expand All @@ -20,7 +20,7 @@ $ composer require inpsyde/assets

## Minimum Requirements and Dependencies

* PHP 7+
* PHP 7.2+
* WordPress latest-2

When installed for development, via Composer, Inpsyde Assets also requires:
Expand Down
22 changes: 14 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
},
{
"name": "Christian Leucht",
"email": "c.leucht@inpsyde.com",
"email": "c.leucht@syde.com",
"homepage": "https://www.chrico.info",
"role": "Developer"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2",
"php": ">=7.4",
"ext-json": "*",
"ext-dom": "*",
"inpsyde/wp-context": "^1.3"
Expand All @@ -29,10 +29,15 @@
"phpunit/phpunit": "^8.5.14 || ^9.0",
"brain/monkey": "^2.5.0",
"mikey179/vfsstream": "^1.6.8",
"inpsyde/php-coding-standards": "^1",
"vimeo/psalm": "@stable",
"syde/phpcs": "^1.0.0",
"phpstan/phpstan": "^2.1.1",
"phpstan/phpstan-mockery": "^2.0.0",
"phpstan/phpstan-phpunit": "^2.0.4",
"szepeviktor/phpstan-wordpress": "^2",
"swissspidy/phpstan-no-private": "^v1.0.0",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"php-stubs/wordpress-stubs": ">=6.2@stable",
"johnpbloch/wordpress-core": ">=6.2"
"johnpbloch/wordpress-core": ">=6.7"
},
"autoload": {
"psr-4": {
Expand All @@ -49,13 +54,14 @@
}
},
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"psalm": "@php ./vendor/bin/psalm --output-format=compact --no-cache",
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"phpstan": "@php ./vendor/bin/phpstan analyse --memory-limit=1G",
"tests": "@php ./vendor/phpunit/phpunit/phpunit",
"tests:no-cov": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
"tests:codecov": "@php ./vendor/phpunit/phpunit/phpunit --coverage-clover coverage.xml",
"qa": [
"@cs",
"@phpcs",
"@phpstan",
"@tests:no-cov"
]
},
Expand Down
2 changes: 1 addition & 1 deletion inc/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Inpsyde\Assets;

// Exit early in case multiple Composer autoloaders try to include this file.
if (defined(__NAMESPACE__.'\BOOTSTRAPPED')) {
if (defined(__NAMESPACE__ . '\BOOTSTRAPPED')) {
return;
}

Expand Down
22 changes: 12 additions & 10 deletions inc/functions.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php # -*- coding: utf-8 -*-
<?php

declare(strict_types=1);

namespace Inpsyde\Assets;

// Exit early in case multiple Composer autoloaders try to include this file.
if (function_exists(__NAMESPACE__.'\\assetSuffix')) {
if (function_exists(__NAMESPACE__ . '\\assetSuffix')) {
return;
}

Expand Down Expand Up @@ -31,11 +33,11 @@ function assetSuffix(): string
function withAssetSuffix(string $file): string
{
$suffix = assetSuffix();
$extension = '.'.pathinfo($file, PATHINFO_EXTENSION);
$extension = '.' . pathinfo($file, PATHINFO_EXTENSION);

return str_replace(
$extension,
$suffix.$extension,
$suffix . $extension,
$file
);
}
Expand All @@ -56,14 +58,14 @@ function symlinkedAssetFolder(string $originDir, string $name): ?string
$originDir = realpath($originDir);

$folderName = '/~inpsyde-assets/';
$rootPath = WP_CONTENT_DIR.$folderName;
$rootUrl = WP_CONTENT_URL.$folderName;
if (! is_dir($rootPath) && ! wp_mkdir_p($rootPath)) {
$rootPath = WP_CONTENT_DIR . $folderName;
$rootUrl = WP_CONTENT_URL . $folderName;
if (!is_dir($rootPath) && !wp_mkdir_p($rootPath)) {
return null;
}

$targetDir = $rootPath.$name;
$targetUrl = trailingslashit($rootUrl.$name);
$targetDir = $rootPath . $name;
$targetUrl = trailingslashit($rootUrl . $name);

if (is_link($targetDir)) {
if (readlink($targetDir) === $originDir) {
Expand All @@ -72,7 +74,7 @@ function symlinkedAssetFolder(string $originDir, string $name): ?string
unlink($targetDir);
}

if (! symlink($originDir, $targetDir)) {
if (!symlink($originDir, $targetDir)) {
return null;
}

Expand Down
47 changes: 12 additions & 35 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
<?xml version="1.0"?>
<ruleset name="Inpsyde Assets Standard">
<ruleset>

<!-- Remove until #6 is merged <file>./inc</file> -->
<file>./src</file>
<file>./tests/phpunit/Unit</file>

<arg value="sp"/>
<arg name="colors"/>
<config name="testVersion" value="7.1-"/>
<config name="ignore_warnings_on_exit" value="1"/>
<config name="testVersion" value="8.1-"/>

<rule ref="Inpsyde"/>
<rule ref="Syde-Extra" />

<rule ref="Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType">
<exclude-pattern>./src/**/*Interface\.php</exclude-pattern>
<exclude-pattern>./src/Asset\.php</exclude-pattern>
</rule>

<rule ref="Inpsyde.CodeQuality.Psr4">
<properties>
<property
name="psr4"
type="array"
value="Inpsyde\Assets=>src,Inpsyde\Assets\Tests=>tests/phpunit"/>
</properties>
</rule>

<!-- We expect inc/ files to both use and declare symbols -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>./inc</exclude-pattern>
<exclude-pattern>./index.php</exclude-pattern>
</rule>

<!-- Relaxed checks for tests -->
<rule ref="WordPress.WP.EnqueuedResources">
<exclude-pattern>./tests</exclude-pattern>
</rule>
<rule ref="Inpsyde.CodeQuality.FunctionLength">
<exclude-pattern>./tests</exclude-pattern>
</rule>
<rule ref="Inpsyde.CodeQuality.ArgumentTypeDeclaration">
<exclude-pattern>./tests</exclude-pattern>
</rule>
<rule ref="Inpsyde.CodeQuality.ReturnTypeDeclaration">
<exclude-pattern>./tests</exclude-pattern>
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">
<element key="src" value="Inpsyde\Assets" />
<element key="tests/phpunit/Unit" value="Inpsyde\Assets\Tests\Unit" />
</property>
</properties>
</rule>
</ruleset>
</ruleset>
18 changes: 18 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-mockery/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/swissspidy/phpstan-no-private/rules.neon
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 6
paths:
- src/
treatPhpDocTypesAsCertain: false
ignoreErrors:
-
message: '#Fetching class constant class of deprecated class#'
path: src/*
-
message: '#Instantiation of deprecated class#'
path: src/*
30 changes: 0 additions & 30 deletions psalm.xml

This file was deleted.

8 changes: 6 additions & 2 deletions src/Asset.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Inpsyde\Assets;

use Inpsyde\Assets\Handler\AssetHandler;
Expand Down Expand Up @@ -108,7 +110,7 @@ public function enqueue(): bool;
*
* @return static
*
* phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType
* phpcs:disable Syde.Functions.ArgumentTypeDeclaration.NoArgumentType
*/
public function canEnqueue($enqueue): Asset;

Expand Down Expand Up @@ -142,6 +144,8 @@ public function filters(): array;
* @param callable|class-string<AssetOutputFilter> ...$filters
*
* @return static
*
* phpcs:disable Syde.Functions.ArgumentTypeDeclaration.NoArgumentType
*/
public function withFilters(...$filters): Asset;

Expand All @@ -160,7 +164,7 @@ public function handler(): string;
public function useHandler(string $handler): Asset;

/**
* @return array
* @return array<mixed>
*/
public function data(): array;

Expand Down
Loading

0 comments on commit e2669fa

Please sign in to comment.