Skip to content

Commit 8d0dcdb

Browse files
committed
feat!: Refactor plugin
1 parent 413ceef commit 8d0dcdb

55 files changed

Lines changed: 4970 additions & 1886 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/qa.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: QA
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
php-versions:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
versions: ${{ steps.versions.outputs.version }}
18+
steps:
19+
- uses: actions/checkout@v6
20+
- id: versions
21+
uses: WyriHaximus/github-action-composer-php-versions-in-range@v1
22+
with:
23+
upcomingReleases: true
24+
25+
unit-tests:
26+
needs: php-versions
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
php: ${{ fromJson(needs.php-versions.outputs.versions) }}
32+
steps:
33+
- uses: actions/checkout@v6
34+
- uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
coverage: none
38+
- uses: ramsey/composer-install@v3
39+
- run: composer test:unit
40+
41+
integration-tests:
42+
needs: php-versions
43+
runs-on: ubuntu-latest
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
php: ${{ fromJson(needs.php-versions.outputs.versions) }}
48+
steps:
49+
- uses: actions/checkout@v6
50+
- uses: shivammathur/setup-php@v2
51+
with:
52+
php-version: ${{ matrix.php }}
53+
coverage: none
54+
- uses: ramsey/composer-install@v3
55+
- run: composer test:integration
56+
57+
static-analysis:
58+
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
59+
60+
coding-standards:
61+
uses: inpsyde/reusable-workflows/.github/workflows/coding-standards-php.yml@main

.github/workflows/tests.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.gitignore

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
vendor
2-
wordpress
3-
wp-content
4-
.phpunit.result.cache
5-
composer.lock
1+
# Composer
2+
/vendor
3+
/composer.lock
4+
5+
# Tests
6+
/wp-content
7+
/.phpunit.result.cache
8+
/tmp

composer.json

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,65 @@
1212
"authors": [
1313
{
1414
"name": "Nicolas Lemoine",
15-
"email": "dev@niconico.fr",
16-
"homepage": "https://github.com/nlemoine"
15+
"email": "nico@n5s.dev",
16+
"homepage": "https://n5s.dev/"
1717
}
1818
],
1919
"homepage": "https://github.com/nlemoine/page-for-custom-post-type",
2020
"support": {
21-
"issues": "https://github.com/nlemoine/page-for-post-type/issues",
22-
"source": "https://github.com/nlemoine/page-for-post-type"
21+
"issues": "https://github.com/nlemoine/page-for-custom-post-type/issues",
22+
"source": "https://github.com/nlemoine/page-for-custom-post-type"
2323
},
2424
"require": {
25-
"composer/installers": "^1.0 || ^2.0"
25+
"composer/installers": "^1.0 || ^2.0",
26+
"php": "^8.2"
2627
},
2728
"require-dev": {
28-
"brain/hierarchy": "^3.2",
29-
"ergebnis/composer-normalize": "^2.28",
30-
"mantle-framework/testkit": "*",
31-
"php-stubs/acf-pro-stubs": "^6.0",
32-
"php-stubs/wordpress-seo-stubs": "^20.5",
33-
"phpstan/extension-installer": "^1.3",
34-
"phpstan/phpstan": "^1.10",
35-
"roots/wordpress": "^6.2",
36-
"symplify/easy-coding-standard": "^11.0",
37-
"szepeviktor/phpstan-wordpress": "^1.3",
38-
"wpackagist-plugin/polylang": "^3.4",
39-
"wpackagist-plugin/wordpress-seo": "^20.9",
40-
"wpsyntex/polylang-stubs": "^3.4"
29+
"ergebnis/composer-normalize": "^2.48",
30+
"mantle-framework/testkit": "^1.17",
31+
"wp-plugin/advanced-custom-fields": "^6",
32+
"wp-plugin/polylang": "^3.4",
33+
"wp-plugin/wordpress-seo": "^26 || ^27",
34+
"wp-plugin/autodescription": "^5.1",
35+
"szepeviktor/phpstan-wordpress": "^2.0",
36+
"phpstan/extension-installer": "^1.4",
37+
"phpstan/phpstan": "^2.1"
4138
},
4239
"repositories": [
4340
{
41+
"name": "wp-packages",
4442
"type": "composer",
45-
"url": "https://wpackagist.org"
43+
"url": "https://repo.wp-packages.org",
44+
"only": [
45+
"wp-plugin/*",
46+
"wp-theme/*"
47+
]
4648
}
4749
],
50+
"minimum-stability": "dev",
51+
"prefer-stable": true,
52+
"autoload": {
53+
"psr-4": {
54+
"n5s\\PageForCustomPostType\\": "src/"
55+
},
56+
"files": [
57+
"src/functions.php"
58+
]
59+
},
60+
"autoload-dev": {
61+
"psr-4": {
62+
"n5s\\PageForCustomPostType\\Tests\\": "tests/"
63+
}
64+
},
4865
"config": {
4966
"allow-plugins": {
67+
"alleyinteractive/composer-wordpress-autoloader": true,
5068
"composer/installers": true,
51-
"roots/wordpress-core-installer": true,
69+
"dealerdirect/phpcodesniffer-composer-installer": true,
5270
"ergebnis/composer-normalize": true,
53-
"alleyinteractive/composer-wordpress-autoloader": true,
71+
"pestphp/pest-plugin": true,
5472
"phpstan/extension-installer": true,
55-
"pestphp/pest-plugin": true
73+
"roots/wordpress-core-installer": true
5674
}
5775
},
5876
"scripts": {
@@ -62,7 +80,14 @@
6280
"cs": "ecs check",
6381
"cs:fix": "ecs check --fix",
6482
"test": [
65-
"PLUGINS=wordpress-seo phpunit --testdox"
66-
]
83+
"@test:core",
84+
"@test:wordpress-seo",
85+
"@test:polylang",
86+
"@test:autodescription"
87+
],
88+
"test:autodescription": "PLUGINS=autodescription phpunit",
89+
"test:core": "phpunit",
90+
"test:polylang": "PLUGINS=polylang phpunit",
91+
"test:wordpress-seo": "PLUGINS=wordpress-seo phpunit"
6792
}
6893
}

ecs.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

phpcs.xml.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<rule ref="Syde-Extra" />
4+
5+
<config name="testVersion" value="8.2-" />
6+
7+
<file>./src</file>
8+
<file>./tests</file>
9+
10+
<arg name="colors" />
11+
<arg value="sp" />
12+
13+
<!-- PSR-4 namespace configuration. -->
14+
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
15+
<properties>
16+
<property name="rootNamespaces" type="array">
17+
<element key="src" value="n5s\PageForCustomPostType" />
18+
<element key="tests" value="n5s\PageForCustomPostType\Tests" />
19+
<element key="tests/unit" value="n5s\PageForCustomPostType\Tests\Unit" />
20+
<element key="tests/integration" value="n5s\PageForCustomPostType\Tests\Integration" />
21+
</property>
22+
</properties>
23+
</rule>
24+
25+
<rule ref="Syde-Extra">
26+
<exclude name="Syde.Files.LineLength.TooLong" />
27+
<exclude name="Syde.Classes.DisallowGetterSetter.GetterFound" />
28+
<exclude name="Syde.NamingConventions.ElementNameMinimalLength.TooShort" />
29+
<exclude name="SlevomatCodingStandard.Classes.ForbiddenPublicProperty.ForbiddenPublicProperty" />
30+
</rule>
31+
32+
</ruleset>

phpstan.neon.dist

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
parameters:
2-
level: 7
2+
level: 8
3+
treatPhpDocTypesAsCertain: false
34
paths:
4-
- src/
5-
editorUrl: 'vscode://file/%%file%%:%%line%%'
5+
- plugin.php
6+
- src
67
scanDirectories:
7-
- wp-content/plugins/wordpress-seo
8-
scanFiles:
9-
- vendor/php-stubs/acf-pro-stubs/acf-pro-stubs.php
10-
- vendor/wpsyntex/polylang-stubs/polylang-stubs.php
8+
- wp-content/plugins

phpunit.xml.dist

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?xml version="1.0"?>
2-
<phpunit
3-
bootstrap="tests/bootstrap.php"
4-
backupGlobals="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
>
10-
<testsuites>
11-
<testsuite name="integrtion">
12-
<directory prefix="test-" suffix=".php">./tests/integration</directory>
13-
</testsuite>
14-
</testsuites>
2+
<phpunit bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true" executionOrder="random">
3+
<testsuites>
4+
<testsuite name="unit">
5+
<directory suffix="Test.php">./tests/Unit</directory>
6+
</testsuite>
7+
<testsuite name="integration">
8+
<directory suffix="Test.php">./tests/Integration</directory>
9+
</testsuite>
10+
</testsuites>
1511
</phpunit>

plugin.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
<?php
2+
23
/**
34
* Plugin Name: Page for custom post type
45
* Plugin URI: https://github.com/nlemoine/page-for-custom-post-type
56
* Description: Allows you to set pages for any custom post type archive
6-
* Version: 0.3.0
7+
* Version: 0.5.0
78
* Author: Nicolas Lemoine
89
* Author URI: https://n5s.dev/
10+
* Requires PHP: 8.2
911
*/
1012

11-
require_once __DIR__ . '/src/plugin.php';
12-
require_once __DIR__ . '/src/functions.php';
13-
add_action('plugins_loaded', function () {
14-
if (!function_exists('PLL')) {
15-
return;
16-
}
17-
require_once __DIR__ . '/src/integrations/polylang.php';
18-
});
19-
require_once __DIR__ . '/src/integrations/wordpress-seo.php';
20-
require_once __DIR__ . '/src/integrations/acf/acf.php';
13+
declare(strict_types=1);
14+
15+
namespace n5s\PageForCustomPostType;
16+
17+
use n5s\PageForCustomPostType\Integration\IntegrationInterface;
2118

22-
// Hook before Polylang
23-
add_action('plugins_loaded', [\n5s\PageForCustomPostType\Plugin::class, 'get_instance'], 0);
19+
// Prevent direct access
20+
if (!defined('ABSPATH')) {
21+
exit;
22+
}
23+
24+
// Initialize plugin (hook before Polylang)
25+
add_action('plugins_loaded', static function (): void {
26+
$plugin = Plugin::getInstance();
27+
$plugin->init();
28+
29+
$container = $plugin->getContainer();
30+
foreach ($plugin->getIntegrations() as $integrationClass) {
31+
$integration = $container->get($integrationClass);
32+
33+
if ($integration->isSupported()) {
34+
$integration->registerHooks();
35+
}
36+
}
37+
}, 0);

0 commit comments

Comments
 (0)