Skip to content

Commit 16abe86

Browse files
committed
Merge commit 'adacdc3' into develop
2 parents 4ba1728 + adacdc3 commit 16abe86

16 files changed

Lines changed: 94 additions & 164 deletions

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ jobs:
2929
- name: Install Nix
3030
uses: DeterminateSystems/determinate-nix-action@v3
3131

32-
- name: Run tests
33-
run: nix flake check
34-
working-directory: dev
32+
- name: Build all checks and outputs
33+
run: |
34+
nix develop -c om ci
35+
cd dev
36+
nix develop -c om ci
3537
3638
- name: Build plugin zip
3739
run: |

.github/workflows/codequality.yml

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

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@
6868
},
6969
"scripts": {
7070
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse",
71-
"phpcbf": "vendor/bin/phpcbf -d memory_limit=512M --standard=./tools/phpcs.xml --extensions=php src tests views *.php",
72-
"phpcs": "vendor/bin/phpcs -d memory_limit=512M -s --standard=./tools/phpcs.xml --extensions=php src tests views *.php",
73-
"php81": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.1 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
74-
"php82": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.2 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
75-
"php83": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.3 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
76-
"php84": "vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.4 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
77-
"phpunit": "vendor/bin/phpunit ./tests/unit/",
78-
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit tests/unit --coverage-html coverage --whitelist src/",
79-
"lint": "vendor/bin/parallel-lint --exclude integration-tests --exclude vendor .",
71+
"phpcbf": "php ./vendor/bin/phpcbf -d memory_limit=512M --standard=./phpcs.xml --extensions=php src tests views *.php",
72+
"phpcs": "php ./vendor/bin/phpcs -d memory_limit=512M -s --standard=./phpcs.xml --extensions=php src tests views *.php",
73+
"php81": "php ./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.1 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
74+
"php82": "php ./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.2 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
75+
"php83": "php ./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.3 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
76+
"php84": "php ./vendor/bin/phpcs --standard=PHPCompatibility --runtime-set testVersion 8.4 --ignore=*/tests/*,*/admin/*,**/coverage/*,*.js,*/vendor/*,*/integration-tests/bedrock/*,*/integration-tests/result*,*/integration-tests/wordpress/* ./",
77+
"phpunit": "php ./vendor/bin/phpunit ./tests/unit/",
78+
"coverage": "XDEBUG_MODE=coverage php ./vendor/bin/phpunit tests/unit --coverage-html coverage --whitelist src/",
79+
"lint": "php ./vendor/bin/parallel-lint --exclude integration-tests --exclude vendor .",
8080
"test": [
8181
"composer validate --strict",
8282
"@lint",
@@ -89,7 +89,7 @@
8989
"@phpunit"
9090
],
9191
"test-integration": "nix flake check ./dev",
92-
"test-integration-live": "WORDPRESS_DIR=$(realpath ./dev/data/wordpress1) vendor/bin/phpunit tests/integration",
92+
"test-integration-live": "WORDPRESS_DIR=$(realpath ./dev/data/wordpress1) php ./vendor/bin/phpunit tests/integration",
9393
"build": "nix build .#plugin"
9494
}
9595
}

dev/flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
extensions = { enabled, all }:
3434
enabled ++ (with all; [ imagick memcached ]);
3535
};
36+
wp2staticLib = inputs.wp2static.lib.${system};
3637
wp2staticPkgs = inputs.wp2static.packages.${system};
3738
wp2static = wp2staticPkgs.plugin;
3839
in {
@@ -129,7 +130,7 @@
129130
toString dbPort
130131
}" --user="${dbUserName}" --password="${dbUserPass}" "${dbName}"
131132
${pkgs.rsync}/bin/rsync -a --copy-links ${wp2staticPkgs.composerVendorDev}/. .
132-
${pkgs.rsync}/bin/rsync -a --copy-links ${wp2staticPkgs.wp2staticSrcDev}/. .
133+
${pkgs.rsync}/bin/rsync -a --copy-links ${wp2staticLib.wp2staticSrcDev}/. .
133134
chmod ug+w -R ./vendor
134135
${phpPackages.composer}/bin/composer dump-autoload
135136
WORDPRESS_DIR="$(realpath ./data/wordpress1)"

flake.nix

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
pname = "${name}-composer-deps";
2525
version = version;
2626
src = composerSrc;
27-
vendorHash = "sha256-22HRb3w2JLmoqi3AtX6RpVCk7QAdMOx0MuOFBzubziU=";
27+
vendorHash = "sha256-3Hi6VYSpfgsTv71O6AhstrJxeuEzJL0Dkhq2HSZCIkI=";
2828
});
2929
composerVendorDev = php.mkComposerVendor (finalAttrs: {
3030
composerNoDev = false;
3131
pname = "${name}-composer-deps-dev";
3232
version = version;
3333
src = composerSrc;
34-
vendorHash = "sha256-P5F8UWN4KPAA5OegcrhZWE/dyeaKUrg2EdHnSM5MMxo=";
34+
vendorHash = "sha256-/38uou7iOaDCZUT3SHXP+opn/SgKRXP+EMx2c8s0EJw=";
3535
});
3636
wp2staticSrc = pkgs.lib.cleanSourceWith {
37-
src = wp2staticSrcDev;
37+
src = self;
3838
filter = path: type:
3939
let base = baseNameOf path;
4040
in type == "directory" && base == "src" || type == "directory"
@@ -50,7 +50,7 @@
5050
&& base == "tests" || pkgs.lib.hasInfix "/tests/" path || type
5151
== "directory" && base == "views" || type == "regular"
5252
&& pkgs.lib.hasSuffix ".php" base || base == "composer.json" || base
53-
== "composer.lock" || base == "phpunit.xml";
53+
== "composer.lock" || base == "phpcs.xml" || base == "phpunit.xml";
5454
};
5555
wp2static = runCommand "wp2static" { } ''
5656
export PLUGIN_DIR="$TMPDIR/${name}"
@@ -65,10 +65,34 @@
6565
cd "$PLUGIN_DIR"/..
6666
${zip}/bin/zip -r -9 $out/wp2static.zip "$(basename "$PLUGIN_DIR")"
6767
'';
68+
wp2staticCheck = stdenv.mkDerivation {
69+
pname = "wp2static-check";
70+
version = version;
71+
72+
src = wp2staticSrcDev;
73+
74+
nativeBuildInputs = [ bash php ];
75+
76+
doBuild = false;
77+
doCheck = true;
78+
79+
checkPhase = ''
80+
TMPDIR="$(realpath ./tmp)"
81+
mkdir -p "$TMPDIR"
82+
export PLUGIN_DIR="$TMPDIR/${name}"
83+
mkdir -p "$PLUGIN_DIR"
84+
cd "$PLUGIN_DIR"
85+
cp -a "${composerVendorDev}/vendor" .
86+
cp -a "$src"/* .
87+
${phpPackages.composer}/bin/composer lint
88+
${phpPackages.composer}/bin/composer phpcs
89+
'';
90+
};
6891
in {
92+
checks = { inherit wp2staticCheck; };
93+
lib = { inherit wp2staticSrcDev wp2staticSrc; };
6994
packages = {
70-
inherit composerVendorDev composerVendor wp2static wp2staticSrcDev
71-
wp2staticSrc;
95+
inherit composerVendorDev composerVendor wp2static;
7296
plugin = wp2static;
7397
};
7498
});

tools/phpcs.xml renamed to phpcs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<exclude name="Squiz.Commenting.FileComment.Missing" />
4747
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
4848
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
49+
<exclude name="Squiz.Commenting.FunctionCommentThrowTag" />
4950
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
5051
<exclude name="Squiz.Commenting.LongConditionClosingComment.SpacingBefore" />
5152
<exclude name="Squiz.Commenting.PostStatementComment.Found" />
@@ -84,6 +85,9 @@
8485
<exclude name="WordPress.PHP.StrictComparisons.LooseComparison" />
8586
<exclude name="WordPress.PHP.StrictInArray.MissingTrueStrict" />
8687
<exclude name="WordPress.PHP.YodaConditions.NotYoda" />
88+
<!-- Forcing exceptions to be escaped is bad practice.
89+
See: https://github.com/WordPress/WordPress-Coding-Standards/issues/2374 -->
90+
<exclude name="WordPress.Security.EscapeOutput.ExceptionNotEscaped"/>
8791
<exclude name="WordPress.Security.EscapeOutput.OutputNotEscaped" />
8892
<exclude name="WordPress.Security.NonceVerification" />
8993
<exclude name="WordPress.Security.ValidatedSanitizedInput" />

src/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public static function wp2staticEnqueueJobs( ?int $post_id = null ): void {
511511
public static function wp2staticToggleAddon( string $addon_slug = null ): void {
512512
if ( defined( 'WP_CLI' ) ) {
513513
if ( ! $addon_slug ) {
514-
throw new WP2StaticException(
514+
throw WsLog::ex(
515515
'No addon slug given for CLI toggling'
516516
);
517517
}

src/Crawler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public static function wp2staticCrawl( string $crawler_slug ): void {
120120
}
121121
$crawled = $url_discovery->discoverURLs( $crawled );
122122
foreach ( $crawled as $_ ) {
123+
// Intentionally empty to consume the iterator
124+
continue;
123125
}
124126

125127
$has_new = true;

src/DetectSitemapsURLs.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ public static function detect( string $wp_site_url, bool $log = false ): \Iterat
163163
}
164164
}
165165
} catch ( WP2StaticException $e ) {
166-
WsLog::l( $e->getMessage() );
167-
throw new WP2StaticException( $e->getMessage(), 0, $e );
166+
throw WsLog::ex( $e->getMessage(), 0, $e );
168167
}
169168
}
170169
}

src/FilesHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public static function deleteDirWithFiles( string $dir ): void {
1717

1818
if ( ! $dir_files ) {
1919
$err = 'Trying to delete nonexistent dir: ' . $dir;
20-
WsLog::l( $err );
21-
throw new WP2StaticException( $err );
20+
throw WsLog::ex( $err );
2221
}
2322

2423
$files = array_diff( $dir_files, [ '.', '..' ] );
@@ -92,8 +91,7 @@ public static function cleanDetectedURLs( array $urls ): array {
9291

9392
if ( ! is_string( $home_url ) ) {
9493
$err = 'Home URL not defined ';
95-
WsLog::l( $err );
96-
throw new WP2StaticException( $err );
94+
throw WsLog::ex( $err );
9795
}
9896

9997
$cleaned_urls = [];

0 commit comments

Comments
 (0)