Changelogger: Fix PHPCS violations (#33664)

This commit is contained in:
Paul Sealock 2022-07-07 08:54:48 +12:00 committed by GitHub
parent 0cebdf5277
commit 7229b65bc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 155 additions and 39 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -15,7 +15,7 @@
"extra": { "extra": {
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../../tools/changelogger/PackageFormatter.php" "filename": "../../../tools/changelogger/class-package-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -36,7 +36,7 @@
}, },
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../tools/changelogger/PluginFormatter.php" "filename": "../../tools/changelogger/class-plugin-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: PHPCS violation fixes

View File

@ -126,7 +126,7 @@
}, },
"changelogger": { "changelogger": {
"formatter": { "formatter": {
"filename": "../../tools/changelogger/LegacyCoreFormatter.php" "filename": "../../tools/changelogger/class-legacy-core-formatter.php"
}, },
"types": { "types": {
"fix": "Fixes an existing bug", "fix": "Fixes an existing bug",

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Formatter class
*
* @package WooCommerce
*/
namespace Automattic\WooCommerce\MonorepoTools\Changelogger; namespace Automattic\WooCommerce\MonorepoTools\Changelogger;
@ -89,16 +94,16 @@ class Formatter extends KeepAChangelogParser {
$release_url = ''; $release_url = '';
if ( strpos( $path[1], 'packages/js/' ) !== false ) { if ( strpos( $path[1], 'packages/js/' ) !== false ) {
$package = substr( $path[1], 12 ); $package = substr( $path[1], 12 );
$release_url ='https://www.npmjs.com/package/@woocommerce/' . $package . '/v/'; $release_url = 'https://www.npmjs.com/package/@woocommerce/' . $package . '/v/';
} else if ( 'plugins/woocommerce' === $path[1] ) { } elseif ( 'plugins/woocommerce' === $path[1] ) {
$release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/'; $release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/';
} else if ( 'plugins/woocommerce-beta-tester' === $path[1] ) { } elseif ( 'plugins/woocommerce-beta-tester' === $path[1] ) {
$release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/'; $release_url = 'https://github.com/woocommerce/woocommerce/releases/tag/';
} else { } else {
throw new \InvalidArgumentException( 'Release URL not found.' ); throw new \InvalidArgumentException( 'Release URL not found.' );
} }
return $release_url . $version; return $release_url . $version;
} }
@ -197,13 +202,13 @@ class Formatter extends KeepAChangelogParser {
$row = preg_replace( '/' . $this->bullet . '/', '', $row, 1 ); $row = preg_replace( '/' . $this->bullet . '/', '', $row, 1 );
$row_segments = explode( ' - ', $row ); $row_segments = explode( ' - ', $row );
$significance = trim( strtolower( $row_segments[0] ) ); $significance = trim( strtolower( $row_segments[0] ) );
array_push( array_push(
$changes, $changes,
array( array(
'subheading' => $is_subentry ? '' : trim( $row_segments[0] ), 'subheading' => $is_subentry ? '' : trim( $row_segments[0] ),
'content' => $is_subentry ? trim( $row ) : trim( isset($row_segments[1]) ? $row_segments[1] : '' ), 'content' => $is_subentry ? trim( $row ) : trim( isset( $row_segments[1] ) ? $row_segments[1] : '' ),
'significance' => in_array( $significance, array( 'patch', 'minor', 'major' ) ) ? $significance : null, 'significance' => in_array( $significance, array( 'patch', 'minor', 'major' ), true ) ? $significance : null,
) )
); );
} }

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Legacy_Core_Formatter class
*
* @package WooCommerce
*/
namespace Automattic\WooCommerce\MonorepoTools\Changelogger; namespace Automattic\WooCommerce\MonorepoTools\Changelogger;
@ -9,14 +14,14 @@ use Automattic\Jetpack\Changelogger\FormatterPlugin;
* Jetpack Changelogger Formatter for WooCommerce plugins * Jetpack Changelogger Formatter for WooCommerce plugins
*/ */
require_once 'Formatter.php'; require_once 'class-formatter.php';
/** /**
* Jetpack Changelogger Formatter for Legacy Core Changelog * Jetpack Changelogger Formatter for Legacy Core Changelog
* *
* Class Formatter * Class Formatter
*/ */
class LegacyCoreFormatter extends Formatter implements FormatterPlugin { class Legacy_Core_Formatter extends Formatter implements FormatterPlugin {
/** /**
* Bullet for changes. * Bullet for changes.
@ -35,13 +40,14 @@ class LegacyCoreFormatter extends Formatter implements FormatterPlugin {
/** /**
* Returns an mapping the subheading to the type key. * Returns an mapping the subheading to the type key.
* *
* @return array * @return array
*/ */
private function getSubheadingTypeMapping() { private function getSubheadingTypeMapping() {
$woocommerce_path = dirname( dirname( __DIR__ ) ) . '/plugins/woocommerce'; $woocommerce_path = dirname( dirname( __DIR__ ) ) . '/plugins/woocommerce';
$composer_file = $woocommerce_path . '/composer.json'; $composer_file = $woocommerce_path . '/composer.json';
$composer_config = json_decode( file_get_contents( $composer_file ), true ); // phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$composer_config = json_decode( file_get_contents( $composer_file ), true );
return array_flip( $composer_config['extra']['changelogger']['types'] ); return array_flip( $composer_config['extra']['changelogger']['types'] );
} }
@ -59,8 +65,8 @@ class LegacyCoreFormatter extends Formatter implements FormatterPlugin {
foreach ( $changelog->getEntries() as $entry ) { foreach ( $changelog->getEntries() as $entry ) {
$version = $entry->getVersion(); $version = $entry->getVersion();
if ( substr_count( $version, '.' ) == 1 ) { if ( substr_count( $version, '.' ) === 1 ) {
$version .= '.0'; $version .= '.0';
} }
$ret .= "= $version YYYY-mm-dd =\n\n"; $ret .= "= $version YYYY-mm-dd =\n\n";

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Package_Formatter class
*
* @package WooCommerce
*/
namespace Automattic\WooCommerce\MonorepoTools\Changelogger; namespace Automattic\WooCommerce\MonorepoTools\Changelogger;
@ -8,14 +13,14 @@ use Automattic\Jetpack\Changelogger\FormatterPlugin;
* Jetpack Changelogger Formatter for WooCommerce packages * Jetpack Changelogger Formatter for WooCommerce packages
*/ */
require_once 'Formatter.php'; require_once 'class-formatter.php';
/** /**
* Jetpack Changelogger Formatter for WooCommerce Packages * Jetpack Changelogger Formatter for WooCommerce Packages
* *
* Class Formatter * Class Formatter
*/ */
class PackageFormatter extends Formatter implements FormatterPlugin { class Package_Formatter extends Formatter implements FormatterPlugin {
/** /**
* Prologue text. * Prologue text.
* *
@ -27,8 +32,8 @@ class PackageFormatter extends Formatter implements FormatterPlugin {
* Return the epilogue string based on the package being released. * Return the epilogue string based on the package being released.
*/ */
public function getEpilogue() { public function getEpilogue() {
$cwd = getcwd(); $cwd = getcwd();
$pos = stripos( $cwd, 'packages/js/' ); $pos = stripos( $cwd, 'packages/js/' );
$package = substr( $cwd, $pos + 12 ); $package = substr( $cwd, $pos + 12 );
return '[See legacy changelogs for previous versions](https://github.com/woocommerce/woocommerce/blob/68581955106947918d2b17607a01bdfdf22288a9/packages/js/' . $package . '/CHANGELOG.md).'; return '[See legacy changelogs for previous versions](https://github.com/woocommerce/woocommerce/blob/68581955106947918d2b17607a01bdfdf22288a9/packages/js/' . $package . '/CHANGELOG.md).';

View File

@ -1,4 +1,9 @@
<?php <?php
/**
* Plugin_Formatter class
*
* @package WooCommerce
*/
namespace Automattic\WooCommerce\MonorepoTools\Changelogger; namespace Automattic\WooCommerce\MonorepoTools\Changelogger;
@ -8,14 +13,14 @@ use Automattic\Jetpack\Changelogger\FormatterPlugin;
* Jetpack Changelogger Formatter for WooCommerce plugins * Jetpack Changelogger Formatter for WooCommerce plugins
*/ */
require_once 'Formatter.php'; require_once 'class-formatter.php';
/** /**
* Jetpack Changelogger Formatter for WooCommerce Plugins * Jetpack Changelogger Formatter for WooCommerce Plugins
* *
* Class Formatter * Class Formatter
*/ */
class PluginFormatter extends Formatter implements FormatterPlugin { class Plugin_Formatter extends Formatter implements FormatterPlugin {
/** /**
* Epilogue text. * Epilogue text.
* *