Skip to content

Commit

Permalink
PHPCS: Clean up some WordPress.WP.AlternativeFunctions sniffs (#28198)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
anomiex authored and matticbot committed Jan 9, 2023
1 parent de69ee3 commit f90ad89
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .phpcs.dir.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset>

<!-- This doesn't run inside of WordPress, do we don't need to use WordPress's alternative functions. -->
<rule ref="WordPress.WP.AlternativeFunctions">
<severity>0</severity>
</rule>

</ruleset>
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/AutoloadFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/CustomAutoloaderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tests/php/bin/test-coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
3 changes: 0 additions & 3 deletions tests/php/lib/class-test-plugin-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
1 change: 0 additions & 1 deletion tests/php/lib/functions-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/php/tests/integration/LoadingGeneratedManifestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f90ad89

Please sign in to comment.