Skip to content

Commit

Permalink
chore: introduce phpcs and phpstan (#159)
Browse files Browse the repository at this point in the history
* chore: introduce phpcs and phpstan
* feat: add phpstan command and expand config
* chore: add phpcs 10-up phpcs file
* chore: update tested PHP version to 8.1
  • Loading branch information
Levdbas authored May 21, 2024
1 parent 2ddc5b9 commit b8dd129
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 33 deletions.
29 changes: 11 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,30 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
php: ['8.1', '8.2']
wp: ['latest']
multisite: ['0', '1']
extensions: ['gd']
experimental: [false]
include:
# WP Trunk
- php: '7.4'
# PHP 8.2 / experimental
- php: '8.2'
wp: 'trunk'
dependency-version: 'highest'
multisite: '0'
experimental: true
# PHP 8.0
- php: '8.0'
wp: 'latest'
# PHP 8.3 / experimental
- php: '8.3'
wp: 'trunk'
dependency-version: 'highest'
multisite: '0'
experimental: false
# PHP 8.1
experimental: true
# Coverage
- php: '8.1'
wp: 'latest'
dependency-version: 'highest'
multisite: '0'
experimental: false
# PHP 8.1 / experimental
- php: '8.1'
wp: 'trunk'
multisite: '0'
experimental: true
# PHP 8.2 / experimental
- php: '8.2'
wp: 'trunk'
multisite: '0'
experimental: true

steps:
- name: Checkout
Expand Down
14 changes: 11 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
},
"require-dev": {
"automattic/wordbless": "^0.4.2",
"yoast/wp-test-utils": "^1.0"
"yoast/wp-test-utils": "^1.0",
"wp-coding-standards/wpcs": "^3.1",
"phpcompatibility/php-compatibility": "^9",
"szepeviktor/phpstan-wordpress": "^1.3",
"10up/phpcs-composer": "^3.0"
},
"extra": {
"installer-paths": {
Expand All @@ -53,10 +57,14 @@
"config": {
"allow-plugins": {
"roots/wordpress-core-installer": true,
"composer/installers": true
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"test": "phpunit"
"test": "phpunit",
"cs": "@php ./vendor/bin/phpcs",
"cs:fix": "@php ./vendor/bin/phpcbf",
"phpstan": "@php ./vendor/bin/phpstan analyse"
}
}
32 changes: 32 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<ruleset>
<!-- Files or directories to check -->
<file>.</file>

<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/wordpress/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/resources/*</exclude-pattern>
<exclude-pattern>*/dist/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>

<!-- Path to strip from the front of file paths inside reports (displays shorter paths) -->
<arg name="basepath" value="." />

<!-- Set a minimum PHP version for PHPCompatibility -->
<config name="testVersion" value="8.1-" />

<rule ref="10up-Default" />
<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
<rule ref="WordPress-Extra" />
<!-- Add VIP-specific rules -->
<config name="minimum_supported_wp_version" value="6.1"/>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array" value="timber-starter"/>
</properties>
</rule>

</ruleset>
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
editorUrl: 'vscode://file/%%file%%:%%line%%'
level: 5 # Increase until "max"
paths:
- src/
- %currentWorkingDirectory%/
excludePaths:
- tests/*
- docs/*
- vendor/*
- wordpress/*
ignoreErrors:

includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
10 changes: 5 additions & 5 deletions tests/TestTimberStarterTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
class TestTimberStarterTheme extends BaseTestCase {

public function set_up() {
switch_theme( basename( dirname( __DIR__ ) ) . '/theme' );
switch_theme(basename(dirname(__DIR__)) . '/theme');

require dirname( __DIR__ ) . '/functions.php';
require dirname(__DIR__) . '/functions.php';

Timber::$dirname = array_merge( (array) Timber::$dirname, [ '../views' ] );
Timber::$dirname = array_unique( Timber::$dirname );
Timber::$dirname = array_merge((array) Timber::$dirname, [ '../views' ]);
Timber::$dirname = array_unique(Timber::$dirname);

// WorDBless includes wp-settings.php
do_action( 'after_setup_theme' );
do_action('after_setup_theme');

parent::set_up();
}
Expand Down
14 changes: 7 additions & 7 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use WorDBless\Load;

if (! file_exists( dirname(__DIR__) . '/wordpress/wp-content')) {
if (! file_exists(dirname(__DIR__) . '/wordpress/wp-content')) {
mkdir(dirname(__DIR__) . '/wordpress/wp-content');
}

Expand All @@ -11,18 +11,18 @@
}

copy(
dirname( __DIR__ ) . '/vendor/automattic/wordbless/src/dbless-wpdb.php',
dirname( __DIR__ ) . '/wordpress/wp-content/db.php'
dirname(__DIR__) . '/vendor/automattic/wordbless/src/dbless-wpdb.php',
dirname(__DIR__) . '/wordpress/wp-content/db.php'
);

$theme_base_name = basename( dirname( __DIR__ ) );
$src = realpath( dirname( dirname( __DIR__ ) ) . '/' . $theme_base_name );
$dest = dirname( __DIR__ ) . '/wordpress/wp-content/themes/' . $theme_base_name;
$theme_base_name = basename(dirname(__DIR__));
$src = realpath(dirname(dirname(__DIR__)) . '/' . $theme_base_name);
$dest = dirname(__DIR__) . '/wordpress/wp-content/themes/' . $theme_base_name;

if ( is_dir($src) && ! file_exists($dest) ) {
symlink($src, $dest);
}

require_once dirname( __DIR__ ) . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/vendor/autoload.php';

Load::load();

0 comments on commit b8dd129

Please sign in to comment.