From f90ad89f5267bd0ad0d2c4ed1f47da0a408ce67f Mon Sep 17 00:00:00 2001 From: anomiex Date: Mon, 9 Jan 2023 17:15:08 +0000 Subject: [PATCH] PHPCS: Clean up some WordPress.WP.AlternativeFunctions sniffs (#28198) In packages/autoloader we can just ignore the sniff entirely. None of the code there runs inside WordPress, so we don't need to use WordPress's alternative functions. The same goes for the tests in packages/my-jetpack. The `Helper_Script_Manager` classes in packages/backup and packages/transport-helper, on the other hand, can make more consistent use of WordPress's `WP_Filesystem` class, instead of mixing it with direct filesystem access. Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/3875919378 --- .phpcs.dir.xml | 9 +++++++++ CHANGELOG.md | 5 +++++ src/AutoloadFileWriter.php | 3 --- src/AutoloadGenerator.php | 3 --- src/CustomAutoloaderPlugin.php | 2 -- tests/php/bin/test-coverage.php | 2 +- tests/php/lib/class-test-plugin-factory.php | 3 --- tests/php/lib/functions-wordpress.php | 1 - .../tests/integration/LoadingGeneratedManifestsTest.php | 2 -- 9 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 .phpcs.dir.xml diff --git a/.phpcs.dir.xml b/.phpcs.dir.xml new file mode 100644 index 000000000..5998613cd --- /dev/null +++ b/.phpcs.dir.xml @@ -0,0 +1,9 @@ + + + + + + 0 + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4c37f86..1633a7260 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.11.15-alpha] - unreleased + +This is an alpha version! The changes listed here are not final. + ## [2.11.14] - 2022-12-19 ### Changed - Use `Composer\ClassMapGenerator\ClassMapGenerator` when available (i.e. with composer 2.4). [#27812] @@ -292,6 +296,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add Custom Autoloader +[2.11.15-alpha]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.14...v2.11.15-alpha [2.11.14]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.13...v2.11.14 [2.11.13]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.12...v2.11.13 [2.11.12]: https://github.com/Automattic/jetpack-autoloader/compare/v2.11.11...v2.11.12 diff --git a/src/AutoloadFileWriter.php b/src/AutoloadFileWriter.php index 9382136a5..e29521d46 100644 --- a/src/AutoloadFileWriter.php +++ b/src/AutoloadFileWriter.php @@ -12,9 +12,6 @@ // phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase // phpcs:disable WordPress.NamingConventions.ValidVariableName.PropertyNotSnakeCase // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite namespace Automattic\Jetpack\Autoloader; diff --git a/src/AutoloadGenerator.php b/src/AutoloadGenerator.php index de543d2cd..35783ed15 100644 --- a/src/AutoloadGenerator.php +++ b/src/AutoloadGenerator.php @@ -12,9 +12,6 @@ // phpcs:disable PHPCompatibility.Keywords.NewKeywords.t_dirFound // phpcs:disable WordPress.Files.FileName.InvalidClassFileName // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_export -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase // phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase diff --git a/src/CustomAutoloaderPlugin.php b/src/CustomAutoloaderPlugin.php index 2bf527d9e..92048d5e7 100644 --- a/src/CustomAutoloaderPlugin.php +++ b/src/CustomAutoloaderPlugin.php @@ -144,7 +144,6 @@ private function determineSuffix() { // Reuse our own suffix, if any. if ( is_readable( $vendorPath . '/autoload_packages.php' ) ) { - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $content = file_get_contents( $vendorPath . '/autoload_packages.php' ); if ( preg_match( '/^namespace Automattic\\\\Jetpack\\\\Autoloader\\\\jp([^;\s]+);/m', $content, $match ) ) { return $match[1]; @@ -153,7 +152,6 @@ private function determineSuffix() { // Reuse Composer's suffix, if any. if ( is_readable( $vendorPath . '/autoload.php' ) ) { - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $content = file_get_contents( $vendorPath . '/autoload.php' ); if ( preg_match( '{ComposerAutoloaderInit([^:\s]+)::}', $content, $match ) ) { return $match[1]; diff --git a/tests/php/bin/test-coverage.php b/tests/php/bin/test-coverage.php index 481969756..4cc53b039 100644 --- a/tests/php/bin/test-coverage.php +++ b/tests/php/bin/test-coverage.php @@ -64,7 +64,7 @@ function get_coverage_version() { */ function count_lines_before_class_keyword( $file ) { // Find the line that the `class` keyword occurs on so that we can use it to calculate an offset from the header. - $content = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + $content = file_get_contents( $file ); // Find the class keyword and capture the number of characters in the string before this point. if ( 0 === preg_match_all( '/^class /m', $content, $matches, PREG_OFFSET_CAPTURE ) ) { diff --git a/tests/php/lib/class-test-plugin-factory.php b/tests/php/lib/class-test-plugin-factory.php index 48d8a57f1..5f9110f24 100644 --- a/tests/php/lib/class-test-plugin-factory.php +++ b/tests/php/lib/class-test-plugin-factory.php @@ -5,9 +5,6 @@ * @package automattic/jetpack-autoloader */ -// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents -// phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec /** diff --git a/tests/php/lib/functions-wordpress.php b/tests/php/lib/functions-wordpress.php index 9e2477d22..ea8ed7662 100644 --- a/tests/php/lib/functions-wordpress.php +++ b/tests/php/lib/functions-wordpress.php @@ -227,7 +227,6 @@ function set_test_is_multisite( $is_multisite ) { * @return false|string The JSON encoded string, or false if it cannot be encoded. */ function wp_json_encode( $data, $options = 0, $depth = 512 ) { - // phpcs:ignore WordPress.WP.AlternativeFunctions.json_encode_json_encode return json_encode( $data, $options, $depth ); } } diff --git a/tests/php/tests/integration/LoadingGeneratedManifestsTest.php b/tests/php/tests/integration/LoadingGeneratedManifestsTest.php index d5bac0acd..fab27e8b7 100644 --- a/tests/php/tests/integration/LoadingGeneratedManifestsTest.php +++ b/tests/php/tests/integration/LoadingGeneratedManifestsTest.php @@ -8,8 +8,6 @@ // We live in the namespace of the test autoloader to avoid many use statements. namespace Automattic\Jetpack\Autoloader\jpCurrent; -// phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents - use Automattic\Jetpack\Autoloader\ManifestGenerator; use PHPUnit\Framework\TestCase;