Skip to content

Commit b8dd129

Browse files
authored
chore: introduce phpcs and phpstan (#159)
* 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
1 parent 2ddc5b9 commit b8dd129

File tree

6 files changed

+81
-33
lines changed

6 files changed

+81
-33
lines changed

.github/workflows/test.yml

+11-18
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,30 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
php: ['7.4', '8.0', '8.1']
29+
php: ['8.1', '8.2']
3030
wp: ['latest']
3131
multisite: ['0', '1']
3232
extensions: ['gd']
3333
experimental: [false]
3434
include:
35-
# WP Trunk
36-
- php: '7.4'
35+
# PHP 8.2 / experimental
36+
- php: '8.2'
3737
wp: 'trunk'
38+
dependency-version: 'highest'
3839
multisite: '0'
3940
experimental: true
40-
# PHP 8.0
41-
- php: '8.0'
42-
wp: 'latest'
41+
# PHP 8.3 / experimental
42+
- php: '8.3'
43+
wp: 'trunk'
44+
dependency-version: 'highest'
4345
multisite: '0'
44-
experimental: false
45-
# PHP 8.1
46+
experimental: true
47+
# Coverage
4648
- php: '8.1'
4749
wp: 'latest'
50+
dependency-version: 'highest'
4851
multisite: '0'
4952
experimental: false
50-
# PHP 8.1 / experimental
51-
- php: '8.1'
52-
wp: 'trunk'
53-
multisite: '0'
54-
experimental: true
55-
# PHP 8.2 / experimental
56-
- php: '8.2'
57-
wp: 'trunk'
58-
multisite: '0'
59-
experimental: true
6053

6154
steps:
6255
- name: Checkout

composer.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
},
4141
"require-dev": {
4242
"automattic/wordbless": "^0.4.2",
43-
"yoast/wp-test-utils": "^1.0"
43+
"yoast/wp-test-utils": "^1.0",
44+
"wp-coding-standards/wpcs": "^3.1",
45+
"phpcompatibility/php-compatibility": "^9",
46+
"szepeviktor/phpstan-wordpress": "^1.3",
47+
"10up/phpcs-composer": "^3.0"
4448
},
4549
"extra": {
4650
"installer-paths": {
@@ -53,10 +57,14 @@
5357
"config": {
5458
"allow-plugins": {
5559
"roots/wordpress-core-installer": true,
56-
"composer/installers": true
60+
"composer/installers": true,
61+
"dealerdirect/phpcodesniffer-composer-installer": true
5762
}
5863
},
5964
"scripts": {
60-
"test": "phpunit"
65+
"test": "phpunit",
66+
"cs": "@php ./vendor/bin/phpcs",
67+
"cs:fix": "@php ./vendor/bin/phpcbf",
68+
"phpstan": "@php ./vendor/bin/phpstan analyse"
6169
}
6270
}

phpcs.xml.dist

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<!-- Files or directories to check -->
4+
<file>.</file>
5+
6+
<exclude-pattern>*/node_modules/*</exclude-pattern>
7+
<exclude-pattern>*/wordpress/*</exclude-pattern>
8+
<exclude-pattern>*/vendor/*</exclude-pattern>
9+
<exclude-pattern>*/resources/*</exclude-pattern>
10+
<exclude-pattern>*/dist/*</exclude-pattern>
11+
<exclude-pattern>*/tests/*</exclude-pattern>
12+
13+
<!-- Path to strip from the front of file paths inside reports (displays shorter paths) -->
14+
<arg name="basepath" value="." />
15+
16+
<!-- Set a minimum PHP version for PHPCompatibility -->
17+
<config name="testVersion" value="8.1-" />
18+
19+
<rule ref="10up-Default" />
20+
<rule ref="WordPress-Core" />
21+
<rule ref="WordPress-Docs" />
22+
<rule ref="WordPress-Extra" />
23+
<!-- Add VIP-specific rules -->
24+
<config name="minimum_supported_wp_version" value="6.1"/>
25+
26+
<rule ref="WordPress.WP.I18n">
27+
<properties>
28+
<property name="text_domain" type="array" value="timber-starter"/>
29+
</properties>
30+
</rule>
31+
32+
</ruleset>

phpstan.neon

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
editorUrl: 'vscode://file/%%file%%:%%line%%'
3+
level: 5 # Increase until "max"
4+
paths:
5+
- src/
6+
- %currentWorkingDirectory%/
7+
excludePaths:
8+
- tests/*
9+
- docs/*
10+
- vendor/*
11+
- wordpress/*
12+
ignoreErrors:
13+
14+
includes:
15+
- vendor/szepeviktor/phpstan-wordpress/extension.neon

tests/TestTimberStarterTheme.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
class TestTimberStarterTheme extends BaseTestCase {
77

88
public function set_up() {
9-
switch_theme( basename( dirname( __DIR__ ) ) . '/theme' );
9+
switch_theme(basename(dirname(__DIR__)) . '/theme');
1010

11-
require dirname( __DIR__ ) . '/functions.php';
11+
require dirname(__DIR__) . '/functions.php';
1212

13-
Timber::$dirname = array_merge( (array) Timber::$dirname, [ '../views' ] );
14-
Timber::$dirname = array_unique( Timber::$dirname );
13+
Timber::$dirname = array_merge((array) Timber::$dirname, [ '../views' ]);
14+
Timber::$dirname = array_unique(Timber::$dirname);
1515

1616
// WorDBless includes wp-settings.php
17-
do_action( 'after_setup_theme' );
17+
do_action('after_setup_theme');
1818

1919
parent::set_up();
2020
}

tests/bootstrap.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use WorDBless\Load;
44

5-
if (! file_exists( dirname(__DIR__) . '/wordpress/wp-content')) {
5+
if (! file_exists(dirname(__DIR__) . '/wordpress/wp-content')) {
66
mkdir(dirname(__DIR__) . '/wordpress/wp-content');
77
}
88

@@ -11,18 +11,18 @@
1111
}
1212

1313
copy(
14-
dirname( __DIR__ ) . '/vendor/automattic/wordbless/src/dbless-wpdb.php',
15-
dirname( __DIR__ ) . '/wordpress/wp-content/db.php'
14+
dirname(__DIR__) . '/vendor/automattic/wordbless/src/dbless-wpdb.php',
15+
dirname(__DIR__) . '/wordpress/wp-content/db.php'
1616
);
1717

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

2222
if ( is_dir($src) && ! file_exists($dest) ) {
2323
symlink($src, $dest);
2424
}
2525

26-
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
26+
require_once dirname(__DIR__) . '/vendor/autoload.php';
2727

2828
Load::load();

0 commit comments

Comments
 (0)