Fix PHPCS errors and warnings

This commit is contained in:
Jeremy Pry 2023-10-26 14:29:49 -05:00 committed by Justin Palmer
parent 5c82baef5b
commit eabda2b61e
No known key found for this signature in database
GPG Key ID: ACAB7C35AA2577AF
10 changed files with 76 additions and 38 deletions

View File

@ -102,4 +102,16 @@
<rule ref="Squiz.Commenting.FileComment.Missing">
<exclude-pattern>tests/php/</exclude-pattern>
</rule>
<rule ref="WordPress.NamingConventions.ValidVariableName">
<exclude-pattern>tests/php/src</exclude-pattern>
</rule>
<rule ref="Squiz.Commenting">
<exclude-pattern>tests/php/src</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride">
<exclude-pattern>tests/php/src</exclude-pattern>
</rule>
</ruleset>

View File

@ -35,8 +35,8 @@ class CustomerHistory {
*/
private function display_customer_history( int $customer_id ) {
// Calculate the data needed for the template.
$order_count = wc_get_customer_order_count( $customer_id );
$total_spent = wc_get_customer_total_spent( $customer_id );
$order_count = wc_get_customer_order_count( $customer_id );
$total_spent = wc_get_customer_total_spent( $customer_id );
$args = array(
'order_count' => $order_count,

View File

@ -37,7 +37,7 @@ class WPConsentAPI {
* @return void
*/
protected function on_plugins_loaded() {
// Include integration to WP Consent Level API if available
// Include integration to WP Consent Level API if available.
if ( ! $this->is_wp_consent_api_active() ) {
return;
}

View File

@ -22,6 +22,9 @@ use WP_User;
* Class SourceAttributionController
*
* @since x.x.x
*
* phpcs:disable WordPress.PHP.DisallowShortTernary
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
class SourceAttributionController implements RegisterHooksInterface {
@ -56,8 +59,9 @@ class SourceAttributionController implements RegisterHooksInterface {
*
* @internal
*
* @param LegacyProxy $proxy The legacy proxy.
* @param WC_Logger_Interface|null $logger The logger object. If not provided, it will be obtained from the proxy.
* @param LegacyProxy $proxy The legacy proxy.
* @param FeaturesController $controller The feature controller.
* @param WC_Logger_Interface $logger The logger object. If not provided, it will be obtained from the proxy.
*/
final public function init( LegacyProxy $proxy, FeaturesController $controller, ?WC_Logger_Interface $logger = null ) {
$this->proxy = $proxy;
@ -183,13 +187,40 @@ class SourceAttributionController implements RegisterHooksInterface {
true
);
/**
* Filter the lifetime of the cookie used for source tracking.
*
* @since x.x.x
*
* @param int $lifetime The lifetime of the cookie in months.
*/
$lifetime = (int) apply_filters( 'wc_order_source_attribution_cookie_lifetime_months', 6 );
/**
* Filter the session length for source tracking.
*
* @since x.x.x
*
* @param int $session_length The session length in minutes.
*/
$session_length = (int) apply_filters( 'wc_order_source_attribution_session_length_minutes', 30 );
/**
* Filter to allow tracking.
*
* @since x.x.x
*
* @param bool $allow_tracking True to allow tracking, false to disable.
*/
$allow_tracking = wc_bool_to_string( apply_filters( 'wc_order_source_attribution_allow_tracking', true ) );
// Pass parameters to Order Source Attribution JS.
$params = array(
'lifetime' => (int) apply_filters( 'wc_order_source_attribution_cookie_lifetime_months', 6 ),
'session' => (int) apply_filters( 'wc_order_source_attribution_session_length_minutes', 30 ),
'lifetime' => $lifetime,
'session' => $session_length,
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'prefix' => $this->field_prefix,
'allowTracking' => wc_bool_to_string( apply_filters( 'wc_order_source_attribution_allow_tracking', true ) ),
'allowTracking' => $allow_tracking,
);
wp_localize_script( 'woocommerce-order-source-attribution-js', 'wc_order_attribute_source_params', $params );
@ -295,7 +326,8 @@ class SourceAttributionController implements RegisterHooksInterface {
/**
* Save source data for an Order object.
*
* @param WC_Order $order The order object.
* @param array $source_data The source data.
* @param WC_Order $order The order object.
*
* @return void
*/

View File

@ -1,12 +1,4 @@
<?php
/**
* Order source attribution meta.
*
* @since x.x.x
*
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
declare( strict_types=1 );
namespace Automattic\WooCommerce\Internal\Traits;
@ -21,6 +13,8 @@ use WP_Post;
* Trait SourceAttributionMeta
*
* @since x.x.x
*
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
trait SourceAttributionMeta {
@ -53,11 +47,13 @@ trait SourceAttributionMeta {
private $field_prefix = '';
/**
* Get the device type based on the other meta fields.
*
* @since x.x.x
*
* @param array $values
* @param array $values The meta values.
*
* @return void
* @return string The device type.
*/
protected function get_device_type( array $values ): string {
$detector = new MobileDetect( array(), $values['user_agent'] );
@ -267,7 +263,7 @@ trait SourceAttributionMeta {
$values['device_type'] = $this->get_device_type( $values );
}
// Set the origin label
// Set the origin label.
if ( array_key_exists( 'type', $values ) && array_key_exists( 'utm_source', $values ) ) {
$values['origin'] = $this->get_origin_label( $values['type'], $values['utm_source'] );
}

View File

@ -12,6 +12,8 @@ use Automattic\WooCommerce\Internal\Traits\ScriptDebug;
* Class TrackingController
*
* @since x.x.x
*
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
class TrackingController implements RegisterHooksInterface {
@ -25,6 +27,8 @@ class TrackingController implements RegisterHooksInterface {
/**
* WCCOMTracking init.
*
* @internal
*
* @param FeaturesController $features_controller Features controller.
*/
final public function init( FeaturesController $features_controller ) {

View File

@ -9,6 +9,8 @@ use Automattic\WooCommerce\Proxies\LegacyProxy;
* Class VersionUtil
*
* @since x.x.x
*
* phpcs:disable Generic.Commenting.DocComment.MissingShort
*/
class VersionUtil {
@ -19,8 +21,9 @@ class VersionUtil {
* Init this class instance.
*
* @since x.x.x
* @internal
*
* @param LegacyProxy $proxy
* @param LegacyProxy $proxy The legacy proxy instance.
*
* @return void
*/

View File

@ -1,15 +1,16 @@
<?php
declare( strict_types=1 );
/**
* Display the Customer History metabox.
*
* This template is used to display the customer history metabox on the edit order screen.
*
* @see Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomerHistory
* @see Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes\CustomerHistory
* @package WooCommerce\Templates
* @version 8.2.0
* @version 8.4.0
*/
declare( strict_types=1 );
defined( 'ABSPATH' ) || exit;
/**

View File

@ -1,15 +1,16 @@
<?php
declare( strict_types=1 );
/**
* Display the Source Data metabox.
*
* This template is used to display the order source data metabox on the edit order screen.
*
* @see Automattic\WooCommerce\Internal\Orders\SourceAttributionController
* @see Automattic\WooCommerce\Internal\Orders\SourceAttributionController
* @package WooCommerce\Templates
* @version 8.2.0
* @version 8.4.0
*/
declare( strict_types=1 );
defined( 'ABSPATH' ) || exit;
/**

View File

@ -15,17 +15,6 @@ class SourceAttributionControllerTest extends WP_UnitTestCase {
protected SourceAttributionController $attribution_fields_class;
/**
* This method is called before the first test of this test class is run.
*
* @codeCoverageIgnore
*
* @return void
*/
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
}
/**
* Sets up the fixture, for example, open a network connection.
*