Skip to content

Commit da60d75

Browse files
committed
Require PHP 7.4, Fix CS and QA
- PHPCS was not checked due to wrong configuration. Fix config (to latest Inpsyde CS) and the fix code - Use typed properties when possible - Use doc bloc consistently, delete unnecessary comments - Update dependencies and GHA workflow (no need to support PHPUnit 8) - Added Package::STATUS_BOOTING constant to alias Package::STATUS_MODULES_ADDED for clarity
1 parent c6855a6 commit da60d75

34 files changed

+916
-966
lines changed

.github/workflows/php-qa.yml

+52-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,60 @@
11
name: Quality assurance PHP
22

3-
on: ['pull_request', 'push', 'workflow_dispatch']
3+
on:
4+
push:
5+
paths:
6+
- '**workflows/php-qa.yml'
7+
- '**.php'
8+
- '**phpcs.xml.dist'
9+
- '**psalm.xml'
10+
- '**composer.json'
11+
pull_request:
12+
paths:
13+
- '**workflows/php-qa.yml'
14+
- '**.php'
15+
- '**phpcs.xml.dist'
16+
- '**psalm.xml'
17+
- '**composer.json'
18+
workflow_dispatch:
19+
inputs:
20+
jobs:
21+
required: true
22+
type: choice
23+
default: 'Run all'
24+
description: 'Choose jobs to run'
25+
options:
26+
- 'Run all'
27+
- 'Run PHPCS only'
28+
- 'Run Psalm only'
29+
- 'Run lint only'
430

531
concurrency:
6-
group: ${{ github.workflow }}-${{ github.ref }}
7-
cancel-in-progress: true
32+
group: "${{ github.workflow }}-${{ github.ref }}"
33+
cancel-in-progress: true
834

935
jobs:
10-
lint-php:
11-
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.event.head_commit.message, 'skip lint')) }}
12-
strategy:
13-
matrix:
14-
php: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
15-
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
16-
with:
17-
PHP_VERSION: ${{ matrix.php }}
36+
lint:
37+
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run lint only')) }}
38+
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
39+
strategy:
40+
matrix:
41+
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
42+
with:
43+
PHP_VERSION: ${{ matrix.php }}
44+
LINT_ARGS: '-e php --colors --show-deprecated ./src'
1845

19-
coding-standards-analysis-php:
20-
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.event.head_commit.message, 'skip cs')) }}
21-
needs: lint-php
22-
uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main
23-
with:
24-
PHPCS_ARGS: '--report=summary'
46+
coding-standards-analysis:
47+
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run PHPCS only')) }}
48+
uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main
49+
with:
50+
PHP_VERSION: '8.3'
2551

26-
static-analysis-php:
27-
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.event.head_commit.message, 'skip sa')) }}
28-
needs: lint-php
29-
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
52+
static-code-analysis:
53+
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }}
54+
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
55+
strategy:
56+
matrix:
57+
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
58+
with:
59+
PHP_VERSION: ${{ matrix.php }}
60+
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress

.github/workflows/php-unit-tests.yml

+65-54
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
11
name: PHP unit tests
22

3-
on: ['pull_request', 'push', 'workflow_dispatch']
3+
on:
4+
push:
5+
paths:
6+
- '**workflows/php-unit-tests.yml'
7+
- '**.php'
8+
- '**phpunit.xml.dist'
9+
- '**composer.json'
10+
pull_request:
11+
paths:
12+
- '**workflows/php-unit-tests.yml'
13+
- '**.php'
14+
- '**phpunit.xml.dist'
15+
- '**composer.json'
16+
workflow_dispatch:
417

518
concurrency:
6-
group: ${{ github.workflow }}-${{ github.ref }}
7-
cancel-in-progress: true
19+
group: "${{ github.workflow }}-${{ github.ref }}"
20+
cancel-in-progress: true
821

922
jobs:
10-
tests-unit-php:
11-
runs-on: ubuntu-latest
12-
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.event.head_commit.message, 'skip tests')) }}
13-
14-
env:
15-
USE_COVERAGE: 'no'
16-
17-
strategy:
18-
matrix:
19-
php-versions: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
20-
dependency-versions: [ 'lowest', 'highest' ]
21-
container-versions: [ '^1.1.0', '^2' ]
22-
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v3
26-
27-
- name: Use coverage?
28-
if: ${{ (matrix.php-versions == '8.0') && (matrix.dependency-versions == 'highest') && (matrix.container-versions == '^2') }}
29-
run: echo "USE_COVERAGE=yes" >> $GITHUB_ENV
30-
31-
- name: Setup PHP
32-
uses: shivammathur/setup-php@v2
33-
with:
34-
php-version: ${{ matrix.php-versions }}
35-
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
36-
coverage: ${{ ((env.USE_COVERAGE == 'yes') && 'xdebug') || 'none' }}
37-
38-
- name: Setup dependencies for PSR-11 target version
39-
run: |
40-
composer remove inpsyde/php-coding-standards inpsyde/wp-stubs-versions vimeo/psalm --dev --no-install
41-
composer require "psr/container:${{ matrix.container-versions }}" --no-install
42-
43-
- name: Install Composer dependencies
44-
uses: ramsey/composer-install@v2
45-
with:
46-
dependency-versions: ${{ matrix.dependency-versions }}
47-
48-
- name: Run unit tests
49-
run: |
50-
./vendor/bin/phpunit --atleast-version 9 && ./vendor/bin/phpunit --migrate-configuration || echo 'Config does not need updates.'
51-
./vendor/bin/phpunit ${{ ((env.USE_COVERAGE == 'yes') && '--coverage-clover coverage.xml') || '--no-coverage' }}
52-
53-
- name: Update coverage
54-
if: ${{ env.USE_COVERAGE == 'yes' }}
55-
uses: codecov/codecov-action@v3
56-
with:
57-
token: ${{ secrets.CODECOV_TOKEN }}
58-
files: ./coverage.xml
59-
flags: unittests
60-
verbose: true
23+
tests-unit-php:
24+
runs-on: ubuntu-latest
25+
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.event.head_commit.message, 'skip tests')) }}
26+
27+
env:
28+
USE_COVERAGE: 'no'
29+
30+
strategy:
31+
matrix:
32+
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
33+
dependency-versions: [ 'lowest', 'highest' ]
34+
container-versions: [ '^1.1.0', '^2' ]
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Use coverage?
41+
if: ${{ (matrix.php-versions == '8.2') && (matrix.dependency-versions == 'highest') && (matrix.container-versions == '^2') }}
42+
run: echo "USE_COVERAGE=yes" >> $GITHUB_ENV
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php-versions }}
48+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
49+
coverage: ${{ ((env.USE_COVERAGE == 'yes') && 'xdebug') || 'none' }}
50+
51+
- name: Setup dependencies for PSR-11 target version
52+
run: |
53+
composer remove inpsyde/php-coding-standards inpsyde/wp-stubs-versions vimeo/psalm --dev --no-install
54+
composer require "psr/container:${{ matrix.container-versions }}" --no-install
55+
56+
- name: Install Composer dependencies
57+
uses: ramsey/composer-install@v3
58+
with:
59+
dependency-versions: ${{ matrix.dependency-versions }}
60+
61+
- name: Run unit tests
62+
run: /vendor/bin/phpunit ${{ ((env.USE_COVERAGE == 'yes') && '--coverage-clover coverage.xml') || '--no-coverage' }}
63+
64+
- name: Update coverage
65+
if: ${{ env.USE_COVERAGE == 'yes' }}
66+
uses: codecov/codecov-action@v4
67+
with:
68+
token: ${{ secrets.CODECOV_TOKEN }}
69+
files: ./coverage.xml
70+
flags: unittests
71+
verbose: true

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
### Composer template
22
composer.phar
33
composer.lock
4-
/vendor/
4+
vendor/
55

66
# PHPUnit
77
.phpunit.result.cache
8+
phpunit.xml
9+
coverage/
810

911
# tmp files
1012
tmp/

composer.json

+24-24
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,30 @@
99
"email": "[email protected]",
1010
"homepage": "https://inpsyde.com/",
1111
"role": "Company"
12-
},
13-
{
14-
"name": "Christian Leucht",
15-
"email": "[email protected]",
16-
"role": "Developer"
17-
},
12+
}
13+
],
14+
"repositories": [
1815
{
19-
"name": "Giuseppe Mazzapica",
20-
"email": "[email protected]",
21-
"role": "Developer"
16+
"type": "composer",
17+
"url": "https://raw.githubusercontent.com/inpsyde/wp-stubs/main",
18+
"only": [
19+
"inpsyde/wp-stubs-versions"
20+
]
2221
}
2322
],
2423
"require": {
25-
"php": ">=7.2",
24+
"php": ">=7.4 <8.4",
2625
"ext-json": "*",
2726
"psr/container": "^1.1.0 || ^2"
2827
},
2928
"require-dev": {
3029
"brain/monkey": "^2.6.1",
31-
"inpsyde/php-coding-standards": "^1",
32-
"mikey179/vfsstream": "^v1.6.10",
33-
"phpunit/phpunit": "^8.5.21 || ^9.6.7",
34-
"vimeo/psalm": "^4.13.1",
35-
"php-stubs/wordpress-stubs": ">=5.8@stable",
36-
"johnpbloch/wordpress-core": ">=5.8"
30+
"inpsyde/php-coding-standards": "^2@dev",
31+
"inpsyde/wp-stubs-versions": "dev-latest",
32+
"roots/wordpress-no-content": "@dev",
33+
"mikey179/vfsstream": "^v1.6.11",
34+
"phpunit/phpunit": "^9.6.19",
35+
"vimeo/psalm": "^5.24.0"
3736
},
3837
"extra": {
3938
"branch-alias": {
@@ -55,19 +54,20 @@
5554
"prefer-stable": true,
5655
"scripts": {
5756
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
58-
"psalm": "@php ./vendor/vimeo/psalm/psalm",
57+
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-suggestions --report-show-info=false --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache --output-format=compact",
58+
"tests": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
59+
"tests:coverage": "@php ./vendor/phpunit/phpunit/phpunit",
5960
"qa": [
60-
"@tests:no-cov",
6161
"@cs",
62-
"@psalm"
63-
],
64-
"tests": "@php ./vendor/phpunit/phpunit/phpunit",
65-
"tests:no-cov": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
62+
"@psalm",
63+
"@tests"
64+
]
6665
},
6766
"config": {
6867
"allow-plugins": {
69-
"dealerdirect/phpcodesniffer-composer-installer": true,
70-
"composer/package-versions-deprecated": true
68+
"composer/*": true,
69+
"inpsyde/*": true,
70+
"dealerdirect/phpcodesniffer-composer-installer": true
7171
}
7272
}
7373
}

phpcs.xml.dist

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
<?xml version="1.0"?>
22
<ruleset>
3-
<file>./src/</file>
4-
<file>./tests/</file>
3+
<file>./src</file>
4+
<file>./tests</file>
55

66
<arg value="sp"/>
77
<arg name="colors"/>
8-
<config name="testVersion" value="7.2-"/>
8+
<config name="testVersion" value="7.4-"/>
99
<config name="ignore_warnings_on_exit" value="1"/>
1010

11+
<rule ref="Inpsyde">
12+
<exclude name="WordPress.PHP.DevelopmentFunctions.error_log_trigger_error" />
13+
</rule>
14+
1115
<rule ref="Inpsyde.CodeQuality.Psr4">
1216
<properties>
1317
<property
1418
name="psr4"
1519
type="array"
16-
value="Inpsyde\Modularity=>src,Inpsyde\Modularity\Tests=>tests/src,Inpsyde\Modularity\Tests\Unit=>tests/unit"/>
20+
value="
21+
Inpsyde\Modularity=>src,
22+
Inpsyde\Modularity\Tests=>tests/src,
23+
Inpsyde\Modularity\Tests\Unit=>tests/unit"
24+
/>
1725
</properties>
1826
</rule>
27+
28+
<rule ref="Inpsyde.CodeQuality.FunctionLength">
29+
<exclude-pattern>*/tests/*</exclude-pattern>
30+
</rule>
31+
<rule ref="Inpsyde.CodeQuality.ForbiddenPublicProperty">
32+
<exclude-pattern>*/tests/*</exclude-pattern>
33+
</rule>
34+
<rule ref="WordPress.PHP.DevelopmentFunctions">
35+
<exclude-pattern>*/tests/*</exclude-pattern>
36+
</rule>
37+
<rule ref="WordPress.PHP.DiscouragedPHPFunctions">
38+
<exclude-pattern>*/tests/*</exclude-pattern>
39+
</rule>
40+
<rule ref="WordPress.Security.EscapeOutput">
41+
<exclude-pattern>*/tests/*</exclude-pattern>
42+
</rule>
1943
</ruleset>

phpunit.xml.dist

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
3-
bootstrap="./tests/boot.php"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
convertDeprecationsToExceptions="false"
9-
backupGlobals="false"
10-
stopOnFailure="false">
11-
<filter>
12-
<whitelist processUncoveredFilesFromWhitelist="true">
1+
<?xml version="1.0"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
bootstrap="./tests/boot.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
convertDeprecationsToExceptions="false"
11+
backupGlobals="false"
12+
stopOnFailure="false">
13+
14+
<coverage processUncoveredFiles="true">
15+
<include>
1316
<directory suffix=".php">./src</directory>
14-
<exclude>
15-
<directory>./vendor</directory>
16-
</exclude>
17-
</whitelist>
18-
</filter>
17+
</include>
18+
<exclude>
19+
<directory>./vendor</directory>
20+
</exclude>
21+
<report>
22+
<html outputDirectory="coverage"/>
23+
</report>
24+
</coverage>
25+
1926
<testsuites>
2027
<testsuite name="Unit">
2128
<directory suffix="Test.php">./tests/unit/</directory>
2229
</testsuite>
2330
</testsuites>
24-
<logging>
25-
<log type="coverage-html" target="tmp"/>
26-
</logging>
31+
2732
</phpunit>

0 commit comments

Comments
 (0)