Move src/Features/WcPayPromotion to /src-internal/Admin/WcPayPromotion (https://github.com/woocommerce/woocommerce-admin/pull/8307)

* Add psr-4 for the internal classes -- this is a temp. changes. We should remove it once we completely merge to the core

* Register class aliases

* Move WcPayPromotion classes to the internal

* Ignore namespace PHP CS issue

* Make features/WcPayPromotion internal

* Added src-internal directory for Automattic\WooCommerce\Internal\Admin namespace

* Moved src/Features/WcPayPromotion to src-internal/Admin/WcPayPromotion

* Add phpcs rules for src-internal

* Remove phpcs:ignoreFile

* Update letter case to make it PSR4 compatible

* Fix letter cases

* Move the alias array into the function

* Rename WcPayPromotion to WCPayPromotion (letter case update)

* Include src-internal

* Update letter case

* Move src/Features/RemoteFreeExtensions to src-internal/Admin/RemoteFreeExtensions (https://github.com/woocommerce/woocommerce-admin/pull/8311)

Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
This commit is contained in:
Moon 2022-02-16 04:50:33 -08:00 committed by GitHub
parent d590b1116f
commit 8023579670
13 changed files with 42 additions and 19 deletions

View File

@ -40,4 +40,5 @@ zip -r "${ZIP_FILE}" \
readme.txt \
changelog.txt \
src/ \
vendor/
vendor/ \
src-internal/

View File

@ -77,7 +77,8 @@
},
"autoload": {
"psr-4": {
"Automattic\\WooCommerce\\Admin\\": "src/"
"Automattic\\WooCommerce\\Admin\\": "src/",
"Automattic\\WooCommerce\\Internal\\Admin\\": "src-internal/Admin/"
}
}
}

View File

@ -31,14 +31,17 @@
<exclude-pattern>src/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>woocommerce-admin.php</exclude-pattern>
<exclude-pattern>src-internal/*</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>src/*</exclude-pattern>
<exclude-pattern>src-internal/*</exclude-pattern>
</rule>
<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
<exclude-pattern>src/*</exclude-pattern>
<exclude-pattern>src-internal/*</exclude-pattern>
</rule>
<rule ref="Generic.Commenting">
@ -46,15 +49,18 @@
</rule>
<rule ref="Squiz.Commenting.FileComment.MissingPackageTag">
<exclude-pattern>src/</exclude-pattern>
<exclude-pattern>src-internal/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting.FileComment.Missing">
<exclude-pattern>src/</exclude-pattern>
<exclude-pattern>src-internal/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
</rule>
<rule ref="Generic.Commenting.Todo">
<exclude-pattern>src/</exclude-pattern>
<exclude-pattern>src-internal/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
</rule>

View File

@ -3,11 +3,10 @@
* Gets a list of fallback methods if remote fetching is disabled.
*/
namespace Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions;
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Init as OnboardingTasks;
/**
* Default Free Extensions

View File

@ -3,7 +3,7 @@
* Evaluates the spec and returns a status.
*/
namespace Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions;
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
defined( 'ABSPATH' ) || exit;

View File

@ -3,12 +3,11 @@
* Handles running payment method specs
*/
namespace Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions;
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\SpecRunner;
use Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\DefaultFreeExtensions;
use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\DefaultFreeExtensions;
/**
* Remote Payment Methods engine.

View File

@ -1,6 +1,6 @@
<?php
namespace Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions;
namespace Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions;
/**
* Specs data source poller class for remote free extensions.

View File

@ -3,7 +3,7 @@
* Handles wcpay promotion
*/
namespace Automattic\WooCommerce\Admin\Features\WcPayPromotion;
namespace Automattic\WooCommerce\Internal\Admin\WCPayPromotion;
defined( 'ABSPATH' ) || exit;
@ -65,7 +65,7 @@ class Init {
*/
public static function possibly_register_pre_install_wc_pay_promotion_gateway( $gateways ) {
if ( self::can_show_promotion() && ! WCPaymentGatewayPreInstallWCPayPromotion::is_dismissed() ) {
$gateways[] = 'Automattic\WooCommerce\Admin\Features\WCPayPromotion\WCPaymentGatewayPreInstallWCPayPromotion';
$gateways[] = 'Automattic\WooCommerce\Internal\Admin\WCPayPromotion\WCPaymentGatewayPreInstallWCPayPromotion';
}
return $gateways;
}
@ -176,7 +176,7 @@ class Init {
* Delete the specs transient.
*/
public static function delete_specs_transient() {
WcPayPromotionDataSourcePoller::get_instance()->delete_specs_transient();
WCPayPromotionDataSourcePoller::get_instance()->delete_specs_transient();
}
/**
@ -186,7 +186,7 @@ class Init {
if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) {
return array();
}
return WcPayPromotionDataSourcePoller::get_instance()->get_specs_from_data_sources();
return WCPayPromotionDataSourcePoller::get_instance()->get_specs_from_data_sources();
}
}

View File

@ -1,13 +1,12 @@
<?php
namespace Automattic\WooCommerce\Admin\Features\WcPayPromotion;
namespace Automattic\WooCommerce\Internal\Admin\WCPayPromotion;
use Automattic\WooCommerce\Admin\DataSourcePoller;
/**
* Specs data source poller class for WooCommerce Payment Promotion.
*/
class WcPayPromotionDataSourcePoller extends DataSourcePoller {
class WCPayPromotionDataSourcePoller extends DataSourcePoller {
const ID = 'payment_method_promotion';

View File

@ -5,7 +5,7 @@
* @package WooCommerce\Admin
*/
namespace Automattic\WooCommerce\Admin\Features\WcPayPromotion;
namespace Automattic\WooCommerce\Internal\Admin\WCPayPromotion;
if ( ! defined( 'ABSPATH' ) ) {
exit;

View File

@ -9,7 +9,7 @@ namespace Automattic\WooCommerce\Admin\API;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\Init as RemoteFreeExtensions;
use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init as RemoteFreeExtensions;
/**
* Onboarding Payments Controller.

View File

@ -54,6 +54,7 @@ class Features {
* Constructor.
*/
public function __construct() {
$this->register_internal_class_aliases();
// Load feature before WooCommerce update hooks.
add_action( 'init', array( __CLASS__, 'load_features' ), 4 );
add_filter( 'woocommerce_get_sections_advanced', array( __CLASS__, 'add_features_section' ) );
@ -389,4 +390,21 @@ class Features {
$admin_body_class = implode( ' ', array_unique( $classes ) );
return " $admin_body_class ";
}
/**
* Alias internal features classes to make them backward compatible.
* We've moved our feature classes to src-internal as part of merging this
* repository with WooCommerce Core to form a monorepo.
* See https://wp.me/p90Yrv-2HY for details.
*/
private function register_internal_class_aliases() {
$aliases = array(
// new class => original class (this will be aliased).
'Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init' => 'Automattic\WooCommerce\Admin\Features\WcPayPromotion\Init',
'Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init' => 'Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\Init',
);
foreach ( $aliases as $new_class => $orig_class ) {
class_alias( $new_class, $orig_class );
}
}
}

View File

@ -4,7 +4,7 @@ namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
use Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\Init as RemoteFreeExtensions;
use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init as RemoteFreeExtensions;
/**
* Marketing Task