From ca06f673a306e22c4414f86f3e40c3b2adc92f80 Mon Sep 17 00:00:00 2001 From: Torben Lundsgaard Date: Tue, 3 Sep 2024 13:53:35 +0200 Subject: [PATCH] Update PHPStan level to 6 --- inc/main.php | 8 +- phpstan.neon.dist | 2 +- src/Admin/AbstractOptionsPage.php | 6 +- src/Admin/AdminAPI.php | 8 +- src/Admin/Analytics.php | 6 +- src/Admin/GeneralOptionsPage.php | 14 ++-- src/Admin/HelpOptionsPage.php | 4 +- src/Admin/Integrations.php | 2 +- src/Admin/IntegrationsOptionsPage.php | 4 +- src/Admin/MetaBox.php | 2 +- src/Admin/Notification.php | 26 +++---- src/Admin/NotificationsHandler.php | 32 ++++---- src/Admin/PluginAvailability.php | 14 ++-- src/Admin/PluginSuggestions.php | 4 +- src/Admin/SetupWizard.php | 4 +- src/Admin/TemplatesOptionsPage.php | 4 +- src/Common/RestAPIServer.php | 6 +- src/Common/Util.php | 67 +++++++++-------- src/Frontend/BasicDatalayerData.php | 30 ++++---- src/Frontend/Frontend.php | 20 ++--- src/Frontend/Stape.php | 4 +- src/Frontend/UserData.php | 6 +- src/Installation/PluginDataImport.php | 14 ++-- src/Installation/Upgrade.php | 2 +- src/Integration/AbstractEcommerce.php | 14 ++-- src/Integration/AbstractIntegration.php | 6 +- src/Integration/ContactForm7.php | 4 +- src/Integration/EasyDigitalDownloads.php | 54 +++++++------- src/Integration/WooCommerce.php | 95 ++++++++++++------------ src/Options.php | 28 +++---- 30 files changed, 246 insertions(+), 244 deletions(-) diff --git a/inc/main.php b/inc/main.php index c8c5e39..bedfe6b 100644 --- a/inc/main.php +++ b/inc/main.php @@ -76,9 +76,9 @@ function gtmkit_plugin_deactivation(): void { /** * Add plugin action links on Plugins page. * - * @param array $links Existing plugin action links. + * @param array $links Existing plugin action links. * - * @return array + * @return array */ function gtmkit_add_plugin_action_link( array $links ): array { @@ -96,9 +96,9 @@ function gtmkit_add_plugin_action_link( array $links ): array { /** * Remove deactivation link. * - * @param array $links Existing plugin action links. + * @param array $links Existing plugin action links. * - * @return array + * @return array */ function gtmkit_remove_deactivation_link( array $links ): array { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ff5cfd2..fe7dcfb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,7 @@ includes: - phar://phpstan.phar/conf/bleedingEdge.neon parameters: - level: 5 + level: 6 treatPhpDocTypesAsCertain: false bootstrapFiles: - bin/phpstan/constants.php diff --git a/src/Admin/AbstractOptionsPage.php b/src/Admin/AbstractOptionsPage.php index 532700a..11c387c 100644 --- a/src/Admin/AbstractOptionsPage.php +++ b/src/Admin/AbstractOptionsPage.php @@ -22,21 +22,21 @@ abstract class AbstractOptionsPage { * * @var string */ - protected $option_name = 'gtmkit'; + protected string $option_name = 'gtmkit'; /** * Plugin options. * * @var Options */ - protected $options; + protected Options $options; /** * Utilities * * @var Util */ - protected $util; + protected Util $util; /** * Constructor. diff --git a/src/Admin/AdminAPI.php b/src/Admin/AdminAPI.php index 3f271fa..87d7993 100644 --- a/src/Admin/AdminAPI.php +++ b/src/Admin/AdminAPI.php @@ -22,14 +22,14 @@ final class AdminAPI { * * @var Options */ - private $options; + private Options $options; /** * An instance of Util. * * @var Util */ - private $util; + private Util $util; /** * Constructor @@ -192,7 +192,7 @@ public function set_notification_status(): void { /** * Validate notification input * - * @param array|null $input The input. + * @param array|null $input The input. * @return bool */ private function validate_notification_input( ?array $input ): bool { @@ -203,7 +203,7 @@ private function validate_notification_input( ?array $input ): bool { /** * Get JSON input * - * @return array|null + * @return array|null */ private function get_json_input(): ?array { $input_raw = file_get_contents( 'php://input' ); diff --git a/src/Admin/Analytics.php b/src/Admin/Analytics.php index f65bd42..0c81888 100644 --- a/src/Admin/Analytics.php +++ b/src/Admin/Analytics.php @@ -20,21 +20,21 @@ final class Analytics { * * @var Analytics */ - public static $instance; + public static Analytics $instance; /** * Plugin options. * * @var Options */ - protected $options; + protected Options $options; /** * Utility * * @var Util */ - private $util; + private Util $util; /** * Constructor. diff --git a/src/Admin/GeneralOptionsPage.php b/src/Admin/GeneralOptionsPage.php index 97bcfee..d075a74 100644 --- a/src/Admin/GeneralOptionsPage.php +++ b/src/Admin/GeneralOptionsPage.php @@ -17,14 +17,14 @@ final class GeneralOptionsPage extends AbstractOptionsPage { * * @var string */ - protected $option_group = 'general'; + protected string $option_group = 'general'; /** * The notifications * - * @var array + * @var array>|int> */ - protected $notifications = []; + protected array $notifications = []; /** * Adds the admin page to the menu. @@ -140,9 +140,9 @@ public function localize_script( string $page_slug, string $script_handle ): voi } /** - * Get the templates + * Get the tutorials * - * @return array + * @return array */ private function get_tutorials(): array { return $this->util->get_data( '/get-tutorials', 'gtmkit_tutorials' ); @@ -151,7 +151,7 @@ private function get_tutorials(): array { /** * Get user roles * - * @return array + * @return array> */ private function get_user_roles(): array { @@ -171,7 +171,7 @@ private function get_user_roles(): array { /** * Get the notifications array * - * @return array + * @return array>|int> */ private function get_notifications_array(): array { if ( empty( $this->notifications ) ) { diff --git a/src/Admin/HelpOptionsPage.php b/src/Admin/HelpOptionsPage.php index c32c526..b93f20e 100644 --- a/src/Admin/HelpOptionsPage.php +++ b/src/Admin/HelpOptionsPage.php @@ -17,7 +17,7 @@ final class HelpOptionsPage extends AbstractOptionsPage { * * @var string */ - protected $option_group = 'help'; + protected string $option_group = 'help'; /** * Configure the options page. @@ -101,7 +101,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi /** * Get the templates * - * @return array + * @return array */ private function get_tutorials(): array { return $this->util->get_data( '/get-tutorials', 'gtmkit_tutorials' ); diff --git a/src/Admin/Integrations.php b/src/Admin/Integrations.php index 9aba25e..7007e93 100644 --- a/src/Admin/Integrations.php +++ b/src/Admin/Integrations.php @@ -15,7 +15,7 @@ final class Integrations { /** * Get the integrations * - * @return array + * @return array> */ public static function get_integrations(): array { diff --git a/src/Admin/IntegrationsOptionsPage.php b/src/Admin/IntegrationsOptionsPage.php index a1886da..eb40874 100644 --- a/src/Admin/IntegrationsOptionsPage.php +++ b/src/Admin/IntegrationsOptionsPage.php @@ -19,7 +19,7 @@ final class IntegrationsOptionsPage extends AbstractOptionsPage { * * @var string */ - protected $option_group = 'integrations'; + protected string $option_group = 'integrations'; /** * Configure the options page. @@ -128,7 +128,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi /** * Get the plugins. * - * @return array + * @return array */ private function get_plugins(): array { $plugins = [ diff --git a/src/Admin/MetaBox.php b/src/Admin/MetaBox.php index 152b296..116117f 100644 --- a/src/Admin/MetaBox.php +++ b/src/Admin/MetaBox.php @@ -19,7 +19,7 @@ final class MetaBox { * * @var Options */ - protected $options; + protected Options $options; /** * Constructor. diff --git a/src/Admin/Notification.php b/src/Admin/Notification.php index 4aa1020..cbde999 100644 --- a/src/Admin/Notification.php +++ b/src/Admin/Notification.php @@ -29,16 +29,16 @@ class Notification { /** * Options of this Notification. * - * @var array + * @var array */ - private $options; + private array $options; /** * The default values for the optional arguments. * - * @var array + * @var array */ - private $defaults = [ + private array $defaults = [ 'id' => '', 'user_id' => null, 'type' => self::NOTICE, @@ -50,21 +50,21 @@ class Notification { * * @var string */ - private $header; + private string $header; /** * The message for the notification. * * @var string */ - private $message; + private string $message; /** * Notification class constructor. * - * @param string $message Message string. - * @param string $header The header. - * @param array $options Set of options. + * @param string $message Message string. + * @param string $header The header. + * @param array $options Set of options. */ public function __construct( string $message, string $header = '', array $options = [] ) { $this->header = $header; @@ -142,7 +142,7 @@ private function has_capability( string $capability ): bool { /** * Return the object properties as an array. * - * @return array + * @return array */ public function to_array(): array { return [ @@ -164,7 +164,7 @@ public function __toString(): string { /** * Renders the notification as an array for use in the settings. * - * @return array The rendered notification. + * @return array The rendered notification. */ public function render(): array { return [ @@ -177,9 +177,9 @@ public function render(): array { /** * Make sure we only have values that we can work with. * - * @param array $options Options to normalize. + * @param array $options Options to normalize. * - * @return array + * @return array */ private function normalize_options( array $options ): array { $options = wp_parse_args( $options, $this->defaults ); diff --git a/src/Admin/NotificationsHandler.php b/src/Admin/NotificationsHandler.php index 3bcdeaf..a92e03c 100644 --- a/src/Admin/NotificationsHandler.php +++ b/src/Admin/NotificationsHandler.php @@ -24,35 +24,35 @@ final class NotificationsHandler { * * @var NotificationsHandler|null */ - private static $instance = null; + private static ?NotificationsHandler $instance = null; /** * Notifications array. * * @var Notification[][] */ - private $notifications = []; + private array $notifications = []; /** * Queued transactions before notifications retrieval. * - * @var array + * @var array}> */ - private $queued_transactions = []; + private array $queued_transactions = []; /** * Flag whether notifications have been retrieved. * * @var bool */ - private $notifications_retrieved = false; + private bool $notifications_retrieved = false; /** * Flag whether notifications need to be updated. * * @var bool */ - private $notifications_need_storage = false; + private bool $notifications_need_storage = false; /** * Constructor. @@ -226,7 +226,7 @@ public function get_notification_by_id( string $notification_id, ?int $user_id = /** * The default notifications array * - * @return array + * @return array> */ private function default_notifications_array(): array { return [ @@ -251,7 +251,7 @@ private function default_notifications_array(): array { /** * Get the notifications for the settings. * - * @return array + * @return array, dismissed: array}|int> */ public function get_notifications_array(): array { $notifications_array = $this->default_notifications_array(); @@ -387,7 +387,7 @@ private static function get_user_id( ?int $user_id ): int { * * @param array|Notification[] $notifications The notifications to split. * - * @return array The notifications, split on user ID. + * @return array The notifications, split on user ID. */ private function split_on_user_id( array $notifications ): array { $split_notifications = []; @@ -547,7 +547,7 @@ private function clear_notifications(): void { * * @param Notification $notification Notification to convert. * - * @return array + * @return array */ private function notification_to_array( Notification $notification ): array { return $notification->to_array(); @@ -556,7 +556,7 @@ private function notification_to_array( Notification $notification ): array { /** * Convert stored array to Notification. * - * @param array $notification_data Array to convert to Notification. + * @param array $notification_data Array to convert to Notification. * * @return Notification */ @@ -582,8 +582,8 @@ private function filter_notification_current_user( Notification $notification ): /** * Queues a notification transaction for later execution if notifications are not yet set up. * - * @param callable $callback Callback that performs the transaction. - * @param array $args Arguments to pass to the callback. + * @param callable $callback Callback that performs the transaction. + * @param array $args Arguments to pass to the callback. * * @return bool True if transaction was queued, false if it can be performed immediately. */ @@ -600,8 +600,8 @@ private function queue_transaction( callable $callback, array $args ): bool { /** * Adds a notification transaction to the queue for later execution. * - * @param callable $callback Callback that performs the transaction. - * @param array $args Arguments to pass to the callback. + * @param callable $callback Callback that performs the transaction. + * @param array $args Arguments to pass to the callback. * * @return void */ @@ -640,7 +640,7 @@ protected function has_stored_notifications(): bool { * * @codeCoverageIgnore * - * @return array|false Array with notifications or false when not set. + * @return array>|false Array with notifications or false when not set. */ protected function get_stored_notifications() { return get_user_option( self::STORAGE_KEY, get_current_user_id() ); diff --git a/src/Admin/PluginAvailability.php b/src/Admin/PluginAvailability.php index 62b5c31..ae1a4df 100644 --- a/src/Admin/PluginAvailability.php +++ b/src/Admin/PluginAvailability.php @@ -15,9 +15,9 @@ final class PluginAvailability { /** * Holds the plugins. * - * @var array + * @var array>> */ - protected $plugins = []; + protected array $plugins = []; /** * Registers the plugins so we can access them. @@ -94,10 +94,10 @@ protected function register_plugins(): void { /** * Normalize plugin * - * @param array $plugin The plugin. - * @param string $id The plugin ID. + * @param array $plugin The plugin. + * @param string $id The plugin ID. * - * @return array Normalized plugin. + * @return array Normalized plugin. */ private function normalize_plugin( array $plugin, string $id ): array { $defaults = [ @@ -117,7 +117,7 @@ private function normalize_plugin( array $plugin, string $id ): array { * * @param string $category Limit the plugins to a category. * - * @return array Array containing the information about the plugins. + * @return array> Array containing the information about the plugins. */ public function get_plugins( string $category = '' ): array { return ( $category ) ? $this->plugins[ $category ] : $this->plugins; @@ -126,7 +126,7 @@ public function get_plugins( string $category = '' ): array { /** * Determines whether a plugin is active. * - * @param array $plugin The plugin to check. + * @param array $plugin The plugin to check. * * @return bool Whether the plugin is active. */ diff --git a/src/Admin/PluginSuggestions.php b/src/Admin/PluginSuggestions.php index 0b15bd1..6c4bd43 100644 --- a/src/Admin/PluginSuggestions.php +++ b/src/Admin/PluginSuggestions.php @@ -130,8 +130,8 @@ protected function get_suggest_seo_plugin_notification( string $notification_id /** * Build conflicting plugin notification. * - * @param string $notification_id The id of the notification to be created. - * @param array $plugin The plugin data. + * @param string $notification_id The id of the notification to be created. + * @param array $plugin The plugin data. * * @return Notification The notification containing the suggested plugin. */ diff --git a/src/Admin/SetupWizard.php b/src/Admin/SetupWizard.php index 81edfbe..2e7e99c 100644 --- a/src/Admin/SetupWizard.php +++ b/src/Admin/SetupWizard.php @@ -29,14 +29,14 @@ final class SetupWizard { * * @var Options */ - protected $options; + protected Options $options; /** * Utilities * * @var Util */ - protected $util; + protected Util $util; /** * Constructor. diff --git a/src/Admin/TemplatesOptionsPage.php b/src/Admin/TemplatesOptionsPage.php index 159cd22..bf303e0 100644 --- a/src/Admin/TemplatesOptionsPage.php +++ b/src/Admin/TemplatesOptionsPage.php @@ -17,7 +17,7 @@ final class TemplatesOptionsPage extends AbstractOptionsPage { * * @var string */ - protected $option_group = 'templates'; + protected string $option_group = 'templates'; /** * Configure the options page. @@ -101,7 +101,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi /** * Get the templates * - * @return array + * @return array */ private function get_templates(): array { return $this->util->get_data( '/get-templates', 'gtmkit_templates' ); diff --git a/src/Common/RestAPIServer.php b/src/Common/RestAPIServer.php index 39792a4..1040fde 100644 --- a/src/Common/RestAPIServer.php +++ b/src/Common/RestAPIServer.php @@ -19,7 +19,7 @@ final class RestAPIServer { * * @var string */ - private $route_namespace = 'gtmkit/v1'; + private string $route_namespace = 'gtmkit/v1'; /** * Permission callback @@ -39,8 +39,8 @@ public function permission_callback() { /** * Register REST route * - * @param string $route The route. - * @param array $args The arguments. + * @param string $route The route. + * @param array $args The arguments. * * @return void */ diff --git a/src/Common/Util.php b/src/Common/Util.php index 780d294..17e0f42 100644 --- a/src/Common/Util.php +++ b/src/Common/Util.php @@ -20,42 +20,42 @@ final class Util { * * @var Options */ - public $options; + public Options $options; /** * Instance of RestAPIServer * * @var RestAPIServer */ - public $rest_api_server; + public RestAPIServer $rest_api_server; /** * Asset path * * @var string */ - public $asset_path; + public string $asset_path; /** * Asset URL * * @var string */ - public $asset_url; + public string $asset_url; /** * API namespace. * * @var string */ - private $api_namespace = '/api/v1'; + private string $api_namespace = '/api/v1'; /** * API host. * * @var string */ - private $api_host; + private string $api_host; /** * Constructor. @@ -88,10 +88,10 @@ public function __construct( Options $options, RestAPIServer $rest_api_server, s /** * Get the site data * - * @param array $options The options. - * @param bool $anonymize Anonymize the data. + * @param array $options The options. + * @param bool $anonymize Anonymize the data. * - * @return array + * @return array */ public function get_site_data( array $options, bool $anonymize = true ): array { @@ -126,12 +126,12 @@ public function get_site_data( array $options, bool $anonymize = true ): array { /** * Set the site data * - * @param array $data Current data. - * @param array $options The options. - * @param string $wp_version The WordPress version. - * @param bool $anonymize Anonymize the data. + * @param array $data Current data. + * @param array $options The options. + * @param string $wp_version The WordPress version. + * @param bool $anonymize Anonymize the data. * - * @return array + * @return array */ private function set_site_data( array $data, array $options, string $wp_version, bool $anonymize ): array { $data['options'] = ( $anonymize ) ? $this->anonymize_options( $options ) : $options; @@ -148,10 +148,10 @@ private function set_site_data( array $data, array $options, string $wp_version, /** * Add shared data * - * @param array $data Current data. - * @param string $wp_version The WordPress version. + * @param array $data Current data. + * @param string $wp_version The WordPress version. * - * @return array + * @return array */ private function add_shared_data( array $data, string $wp_version ): array { $data['shared_data'] = [ @@ -203,7 +203,7 @@ private function add_shared_data( array $data, string $wp_version ): array { /** * Gets names of all active plugins. * - * @return array An array of active plugins names. + * @return array An array of active plugins names. */ public function get_active_plugins(): array { @@ -224,12 +224,12 @@ public function get_active_plugins(): array { /** * Add plugin to array if active. * - * @param string $plugin The plugin slug. - * @param string $key The key. - * @param array $data The data. - * @param bool $shorten Shorten the version number or not. + * @param string $plugin The plugin slug. + * @param string $key The key. + * @param array $data The data. + * @param bool $shorten Shorten the version number or not. * - * @return array An array of active plugins names. + * @return array An array of active plugins names. */ public function add_active_plugin_and_version( string $plugin, string $key, array $data, bool $shorten = true ): array { @@ -244,9 +244,9 @@ public function add_active_plugin_and_version( string $plugin, string $key, arra /** * Anonymize options * - * @param array $options The options. + * @param array $options The options. * - * @return array + * @return array */ public function anonymize_options( array $options ): array { @@ -310,15 +310,18 @@ public function get_plugin_version(): string { /** * Enqueue script in build * - * @param string $handle The script handle. - * @param string $script The script name. - * @param bool $has_asset_file If the script has an asset file or not. - * @param array $deps The script dependencies. - * @param array $args The loading strategy. + * @param string $handle The script handle. + * @param string $script The script name. + * @param bool $has_asset_file If the script has an asset file or not. + * @param array $deps The script dependencies. + * @param array $args The loading strategy. * * @return void */ - public function enqueue_script( string $handle, string $script, bool $has_asset_file = false, array $deps = [], array $args = [ 'strategy' => 'defer' ] ): void { + public function enqueue_script( string $handle, string $script, bool $has_asset_file = false, array $deps = [], array $args = [ + 'strategy' => 'defer', + 'in_footer' => false, + ] ): void { $ver = $this->get_plugin_version(); @@ -351,7 +354,7 @@ public function enqueue_script( string $handle, string $script, bool $has_asset_ * @param string $endpoint The API endpoint. * @param string $transient The transient. * - * @return array + * @return array */ public function get_data( string $endpoint, string $transient ): array { $data = get_transient( $transient ); diff --git a/src/Frontend/BasicDatalayerData.php b/src/Frontend/BasicDatalayerData.php index 43512e4..19744ef 100644 --- a/src/Frontend/BasicDatalayerData.php +++ b/src/Frontend/BasicDatalayerData.php @@ -19,21 +19,21 @@ final class BasicDatalayerData { * * @var Options */ - protected $options; + protected Options $options; /** * Set datalayer post type. * * @var bool */ - protected $set_datalayer_post_type; + protected bool $set_datalayer_post_type; /** * Set datalayer page type. * * @var bool */ - protected $set_datalayer_page_type; + protected bool $set_datalayer_page_type; /** * Constructor. @@ -61,9 +61,9 @@ public static function register( Options $options ): void { /** * Get the basic dataLayer data * - * @param array $datalayer The datalayer. + * @param array $datalayer The datalayer. * - * @return array + * @return array */ public function get_datalayer_content( array $datalayer ): array { @@ -96,11 +96,11 @@ public function get_datalayer_content( array $datalayer ): array { /** * Set post and page types in the datalayer * - * @param array $datalayer The datalayer. - * @param string $post_type The post type. - * @param string $page_type The page type. + * @param array $datalayer The datalayer. + * @param string $post_type The post type. + * @param string $page_type The page type. * - * @return array + * @return array */ private function set_post_and_page_types( array $datalayer, string $post_type, string $page_type = '' ): array { @@ -117,9 +117,9 @@ private function set_post_and_page_types( array $datalayer, string $post_type, s /** * Get priority dataLayer data * - * @param array $datalayer The datalayer. + * @param array $datalayer The datalayer. * - * @return array + * @return array */ public function get_priority_datalayer_content( array $datalayer ): array { @@ -135,9 +135,9 @@ public function get_priority_datalayer_content( array $datalayer ): array { /** * Get the dataLayer data for singular post types * - * @param array $datalayer The datalayer. + * @param array $datalayer The datalayer. * - * @return array + * @return array */ private function get_singular_datalayer_content( array $datalayer ): array { @@ -188,9 +188,9 @@ private function get_singular_datalayer_content( array $datalayer ): array { /** * Get the dataLayer data for site search * - * @param array $datalayer The datalayer. + * @param array $datalayer The datalayer. * - * @return array + * @return array */ private function get_site_search_datalayer_content( array $datalayer ): array { global $wp_query; diff --git a/src/Frontend/Frontend.php b/src/Frontend/Frontend.php index 78f19e8..1c6eaa4 100644 --- a/src/Frontend/Frontend.php +++ b/src/Frontend/Frontend.php @@ -19,14 +19,14 @@ final class Frontend { * * @var Options */ - protected $options; + protected Options $options; /** * Datalayer name. * * @var string */ - protected $datalayer_name; + protected string $datalayer_name; /** * Constructor. @@ -253,10 +253,10 @@ public function get_gtm_script( string $gtm_id ): void { /** * Set inline script attributes * - * @param array $attributes The script attributes. - * @param string $script The script. + * @param array $attributes The script attributes. + * @param string $script The script. * - * @return array The script attributes. + * @return array The script attributes. */ public function set_inline_script_attributes( array $attributes, string $script ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed if ( isset( $attributes['id'] ) && strpos( $attributes['id'], 'gtmkit-' ) === 0 ) { @@ -310,9 +310,9 @@ public function container_disabled(): void { /** * Exclude GTM Kit in WP Rocket * - * @param array $pattern The exclude list. + * @param array $pattern The exclude list. * - * @return array + * @return array */ public function wp_rocket_exclude_javascript( array $pattern ): array { $pattern[] = 'dataLayer'; @@ -324,10 +324,10 @@ public function wp_rocket_exclude_javascript( array $pattern ): array { /** * Adds Google Tag Manager domain DNS Prefetch printed by wp_resource_hints * - * @param array $hints URLs to print for resource hints. - * @param string $relation_type The relation type the URL are printed for. + * @param array $hints URLs to print for resource hints. + * @param string $relation_type The relation type the URL are printed for. * - * @return array URL to print + * @return array URL to print */ public function dns_prefetch( array $hints, string $relation_type ): array { diff --git a/src/Frontend/Stape.php b/src/Frontend/Stape.php index 4c3a7c6..5b5ef30 100644 --- a/src/Frontend/Stape.php +++ b/src/Frontend/Stape.php @@ -26,7 +26,7 @@ final class Stape { * * @var Options */ - protected $options; + protected Options $options; /** * Constructor. @@ -94,7 +94,7 @@ private function delete_cookie(): void { /** * Set cookie. * - * @param array $args Parameters. + * @param array $args Parameters. * @return void */ private function set_cookie( array $args ): void { diff --git a/src/Frontend/UserData.php b/src/Frontend/UserData.php index b921cd8..6e3027a 100644 --- a/src/Frontend/UserData.php +++ b/src/Frontend/UserData.php @@ -19,7 +19,7 @@ final class UserData { * * @var Options */ - protected $options; + protected Options $options; /** * Constructor. @@ -44,9 +44,9 @@ public static function register( Options $options ): void { /** * Get the dataLayer content * - * @param array $datalayer The datalayer. + * @param array $datalayer The datalayer. * - * @return array + * @return array */ public function get_datalayer_content( array $datalayer ): array { diff --git a/src/Installation/PluginDataImport.php b/src/Installation/PluginDataImport.php index 5c820cf..12f40ed 100644 --- a/src/Installation/PluginDataImport.php +++ b/src/Installation/PluginDataImport.php @@ -15,7 +15,7 @@ class PluginDataImport { /** * Get the data for all plugins. * - * @return array + * @return array */ public function get_all(): array { @@ -54,7 +54,7 @@ public function get_all(): array { * * @param string $slug The plugin slug. * - * @return array + * @return array */ public function get( string $slug ): array { @@ -87,7 +87,7 @@ private function extract_container_id( string $container_script ): string { /** * Check if GTM4WP plugin settings are present and extract them. * - * @return array + * @return array */ private function get_gtm4wp(): array { @@ -132,7 +132,7 @@ private function get_gtm4wp(): array { /** * Check if GTM for WooCommerce plugin settings are present and extract them. * - * @return array + * @return array */ private function get_gtm_for_woocommerce(): array { @@ -157,7 +157,7 @@ private function get_gtm_for_woocommerce(): array { /** * Check if Metronet Tag Manager plugin settings are present and extract them. * - * @return array + * @return array */ private function get_metronet_tag_manager(): array { @@ -184,7 +184,7 @@ private function get_metronet_tag_manager(): array { /** * Check if Google Analytics and Google Tag Manager plugin settings are present and extract them. * - * @return array + * @return array */ private function get_google_analytics_and_google_tag_manager(): array { @@ -206,7 +206,7 @@ private function get_google_analytics_and_google_tag_manager(): array { /** * Check if Google Tag Manager plugin settings are present and extract them. * - * @return array + * @return array */ private function get_google_tag_manager(): array { diff --git a/src/Installation/Upgrade.php b/src/Installation/Upgrade.php index e215809..0a70ba7 100644 --- a/src/Installation/Upgrade.php +++ b/src/Installation/Upgrade.php @@ -34,7 +34,7 @@ public function __construct() { /** * Get upgrades if applicable. * - * @return array + * @return array */ protected function get_upgrades(): array { diff --git a/src/Integration/AbstractEcommerce.php b/src/Integration/AbstractEcommerce.php index eef7981..8032328 100644 --- a/src/Integration/AbstractEcommerce.php +++ b/src/Integration/AbstractEcommerce.php @@ -21,21 +21,21 @@ abstract class AbstractEcommerce extends AbstractIntegration { * * @var string */ - protected $store_currency; + protected string $store_currency; /** * Grouped product list position. * * @var int */ - protected $grouped_product_position; + protected int $grouped_product_position; /** * Global data. * - * @var array + * @var array */ - protected $global_data; + protected array $global_data; /** * Constructor. @@ -53,7 +53,7 @@ public function __construct( Options $options, Util $util ) { /** * Get instance */ - abstract public static function instance(); + abstract public static function instance(): self; /** * Register frontend @@ -69,7 +69,7 @@ abstract public static function register( Options $options, Util $util ): void; * @param int $product_id The product ID. * @param string $taxonomy The taxonomy slug. * - * @return array The category breadcrumb for the given product ID. + * @return array The category breadcrumb for the given product ID. */ public function get_primary_product_category( int $product_id, string $taxonomy ): array { @@ -117,7 +117,7 @@ public function get_primary_product_category( int $product_id, string $taxonomy * @param int $category_id The ID of the product category. * @param string $taxonomy The taxonomy slug. * - * @return array The category path elements as an array. + * @return array The category path elements as an array. */ public function get_category_breadcrumb( int $category_id, string $taxonomy ): array { static $categories = []; diff --git a/src/Integration/AbstractIntegration.php b/src/Integration/AbstractIntegration.php index 85c2377..f294c92 100644 --- a/src/Integration/AbstractIntegration.php +++ b/src/Integration/AbstractIntegration.php @@ -20,14 +20,14 @@ abstract class AbstractIntegration { * * @var Options */ - protected $options; + protected Options $options; /** * Utilities * * @var Util */ - protected $util; + protected Util $util; /** * Constructor. @@ -43,7 +43,7 @@ public function __construct( Options $options, Util $util ) { /** * Get instance */ - abstract public static function instance(); + abstract public static function instance(): self; /** * Register frontend diff --git a/src/Integration/ContactForm7.php b/src/Integration/ContactForm7.php index 24c2b70..ce00e8b 100644 --- a/src/Integration/ContactForm7.php +++ b/src/Integration/ContactForm7.php @@ -19,9 +19,9 @@ final class ContactForm7 extends AbstractIntegration { /** * Instance. * - * @var ContactForm7 An instance of ContactForm7. + * @var null|ContactForm7 An instance of ContactForm7. */ - protected static $instance = null; + protected static ?ContactForm7 $instance = null; /** * Get instance diff --git a/src/Integration/EasyDigitalDownloads.php b/src/Integration/EasyDigitalDownloads.php index 57cc5b4..39a94f4 100644 --- a/src/Integration/EasyDigitalDownloads.php +++ b/src/Integration/EasyDigitalDownloads.php @@ -23,9 +23,9 @@ final class EasyDigitalDownloads extends AbstractEcommerce { /** * Instance. * - * @var EasyDigitalDownloads + * @var null|EasyDigitalDownloads */ - protected static $instance = null; + protected static ?EasyDigitalDownloads $instance = null; /** * Constructor. @@ -92,9 +92,9 @@ public function enqueue_scripts(): void { /** * Get the global script settings * - * @param array $global_settings Script settings. + * @param array $global_settings Script settings. * - * @return array + * @return array */ public function get_global_settings( array $global_settings ): array { @@ -110,9 +110,9 @@ public function get_global_settings( array $global_settings ): array { /** * Get the global script data * - * @param array $global_data Script data. + * @param array $global_data Script data. * - * @return array + * @return array */ public function get_global_data( array $global_data ): array { @@ -133,9 +133,9 @@ public function get_global_data( array $global_data ): array { /** * Get the dataLayer content * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content( array $data_layer ): array { @@ -157,9 +157,9 @@ public function get_datalayer_content( array $data_layer ): array { /** * Get the dataLayer data for product pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_page( array $data_layer ): array { @@ -187,9 +187,9 @@ public function get_datalayer_content_product_page( array $data_layer ): array { /** * Get the dataLayer data for category pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_category( array $data_layer ): array { @@ -203,9 +203,9 @@ public function get_datalayer_content_product_category( array $data_layer ): arr /** * Get the dataLayer data for product tag pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_tag( array $data_layer ): array { @@ -219,9 +219,9 @@ public function get_datalayer_content_product_tag( array $data_layer ): array { /** * Get the dataLayer data for checkout page * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_checkout( array $data_layer ): array { if ( $this->options->get( 'general', 'datalayer_page_type' ) ) { @@ -239,9 +239,9 @@ public function get_datalayer_content_checkout( array $data_layer ): array { /** * Get the dataLayer data for order_received page * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_order_received( array $data_layer ): array { @@ -333,7 +333,7 @@ public function get_datalayer_content_order_received( array $data_layer ): array * * @param string $event_context The event context of the item data. * - * @return array The cart items. + * @return array The cart items. */ public function get_cart_items( string $event_context ): array { $cart_items = []; @@ -351,12 +351,12 @@ public function get_cart_items( string $event_context ): array { /** * Get item data. * - * @param EDD_Download $download An instance of EDD_Download. - * @param array $options Optional options. - * @param array $additional_item_attributes Any key-value pair that needs to be added to the item data. - * @param string $event_context The event context of the item data. + * @param EDD_Download $download An instance of EDD_Download. + * @param array $options Optional options. + * @param array $additional_item_attributes Any key-value pair that needs to be added to the item data. + * @param string $event_context The event context of the item data. * - * @return array The item data. + * @return array The item data. */ public function get_item_data( EDD_Download $download, array $options = [], array $additional_item_attributes = [], string $event_context = '' ): array { @@ -412,10 +412,10 @@ public function get_item_data( EDD_Download $download, array $options = [], arra /** * Include customer data * - * @param array $data_layer The datalayer content. - * @param Order|false $order Order. + * @param array $data_layer The datalayer content. + * @param Order|false $order Order. * - * @return array The datalayer. + * @return array The datalayer. */ public function include_customer_data( array $data_layer, $order ): array { diff --git a/src/Integration/WooCommerce.php b/src/Integration/WooCommerce.php index 50fb349..4312288 100644 --- a/src/Integration/WooCommerce.php +++ b/src/Integration/WooCommerce.php @@ -31,9 +31,9 @@ final class WooCommerce extends AbstractEcommerce { /** * Instance. * - * @var WooCommerce + * @var null|WooCommerce */ - protected static $instance = null; + protected static ?WooCommerce $instance = null; /** * Stores Rest Extending instance. @@ -233,9 +233,9 @@ public function enqueue_scripts(): void { /** * Get the global script settings * - * @param array $global_settings Script settings. + * @param array $global_settings Script settings. * - * @return array + * @return array */ public function get_global_settings( array $global_settings ): array { @@ -271,9 +271,9 @@ public function get_global_settings( array $global_settings ): array { /** * Get the global script data * - * @param array $global_data Script data. + * @param array $global_data Script data. * - * @return array + * @return array */ public function get_global_data( array $global_data ): array { @@ -319,9 +319,9 @@ private function get_payment_method(): ?string { /** * Get the WooCommerce dataLayer content * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content( array $data_layer ): array { @@ -353,9 +353,9 @@ public function get_datalayer_content( array $data_layer ): array { /** * Get the dataLayer data for product pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_page( array $data_layer ): array { @@ -389,9 +389,9 @@ public function get_datalayer_content_product_page( array $data_layer ): array { /** * Get the dataLayer data for category pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_category( array $data_layer ): array { @@ -405,9 +405,9 @@ public function get_datalayer_content_product_category( array $data_layer ): arr /** * Get the dataLayer data for product tag pages * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_product_tag( array $data_layer ): array { @@ -421,9 +421,9 @@ public function get_datalayer_content_product_tag( array $data_layer ): array { /** * Get the dataLayer data for cart page * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_cart( array $data_layer ): array { @@ -450,9 +450,9 @@ public function get_datalayer_content_cart( array $data_layer ): array { /** * Get the dataLayer data for checkout page * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_checkout( array $data_layer ): array { @@ -483,9 +483,9 @@ public function get_datalayer_content_checkout( array $data_layer ): array { /** * Get the dataLayer data for order_received page * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_datalayer_content_order_received( array $data_layer ): array { @@ -555,10 +555,10 @@ public function get_datalayer_content_order_received( array $data_layer ): array /** * Retrieves purchase event data for the data layer. * - * @param WC_Order $order The order. - * @param array $data_layer The datalayer content. + * @param WC_Order $order The order. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content. + * @return array The datalayer content. */ public function get_purchase_event( WC_Order $order, array $data_layer = [] ): array { @@ -603,9 +603,9 @@ public function get_purchase_event( WC_Order $order, array $data_layer = [] ): a /** * Get the permalinkStructure property for the dataLayer * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ private function get_permalink_structure_property( array $data_layer ): array { $wc_permalink_structure = \wc_get_permalink_structure(); @@ -622,9 +622,9 @@ private function get_permalink_structure_property( array $data_layer ): array { /** * Get the pages property for the dataLayer * - * @param array $data_layer The datalayer content. + * @param array $data_layer The datalayer content. * - * @return array The datalayer content + * @return array The datalayer content */ public function get_pages_property( array $data_layer ): array { $data_layer['pages'] = [ @@ -642,7 +642,7 @@ public function get_pages_property( array $data_layer ): array { * * @param string $event_context The event context of the item data. * - * @return array The cart items. + * @return array The cart items. */ public function get_cart_items( string $event_context ): array { $cart_items = []; @@ -681,11 +681,11 @@ public function get_cart_items( string $event_context ): array { /** * Get item data. * - * @param WC_Product $product An instance of WP_Product. - * @param array $additional_item_attributes Any key-value pair that needs to be added to the item data. - * @param string $event_context The event context of the item data. + * @param WC_Product $product An instance of WP_Product. + * @param array $additional_item_attributes Any key-value pair that needs to be added to the item data. + * @param string $event_context The event context of the item data. * - * @return array The item data. + * @return array The item data. */ public function get_item_data( $product, array $additional_item_attributes = [], string $event_context = '' ): array { @@ -741,10 +741,10 @@ public function get_item_data( $product, array $additional_item_attributes = [], /** * Get the coupons and discount for an item * - * @param array $coupons The coupons. - * @param array $item The item. + * @param array $coupons The coupons. + * @param array $item The item. * - * @return array + * @return array */ public function get_coupon_discount( array $coupons, array $item ): array { @@ -1048,9 +1048,9 @@ public function prefix_item_id( string $item_id = '' ): string { /** * Compatibility with TI WooCommerce Wishlist * - * @param array $item_data Item data. + * @param array $item_data Item data. * - * @return array + * @return array */ public function Compatibility_With_TI_Wishlist( array $item_data ): array { @@ -1095,7 +1095,7 @@ public function extend_store(): void { * * @param WC_Product $product Current product data. * - * @return array $product Registered data or empty array if condition is not satisfied. + * @return array $product Registered data or empty array if condition is not satisfied. */ public function extend_product_data( $product ): array { return array( @@ -1106,9 +1106,9 @@ public function extend_product_data( $product ): array { /** * Register GTM data into products endpoint. * - * @param array $cart_item Cart item data. + * @param array $cart_item Cart item data. * - * @return array $product Registered data or empty array if condition is not satisfied. + * @return array $product Registered data or empty array if condition is not satisfied. */ public function extend_cart_data( array $cart_item ): array { return array( @@ -1116,11 +1116,10 @@ public function extend_cart_data( array $cart_item ): array { ); } - /** * Register subscription product schema into cart/items endpoint. * - * @return array Registered schema. + * @return array Registered schema. */ public function extend_product_schema(): array { @@ -1138,7 +1137,7 @@ public function extend_product_schema(): array { * * @param int $post_id The post ID. * - * @return array + * @return array */ public function has_woocommerce_blocks( int $post_id ): array { $post_content = get_the_content( null, false, $post_id ); @@ -1161,7 +1160,7 @@ public function has_woocommerce_blocks( int $post_id ): array { /** * Get WooCommerce blocks * - * @return array + * @return array */ public function get_woocommerce_blocks(): array { return $this->has_woocommerce_blocks( get_the_ID() ); @@ -1170,10 +1169,10 @@ public function get_woocommerce_blocks(): array { /** * Include customer data * - * @param array $data_layer The datalayer content. - * @param mixed $order_value Order value. + * @param array $data_layer The datalayer content. + * @param mixed $order_value Order value. * - * @return array + * @return array */ public function include_customer_data( array $data_layer, $order_value ): array { @@ -1242,7 +1241,7 @@ public function include_customer_data( array $data_layer, $order_value ): array * * @param WC_Order $order The order. * - * @return array + * @return array */ private function get_order_items( WC_Order $order ): array { $order_items = []; diff --git a/src/Options.php b/src/Options.php index 8114041..b8724fc 100644 --- a/src/Options.php +++ b/src/Options.php @@ -22,16 +22,16 @@ final class Options { /** * All the options. * - * @var array + * @var array */ - private $options; + private array $options; /** * Map of all the default options * - * @var array + * @var array>> */ - private static $map = [ + private static array $map = [ 'general' => [ 'gtm_id' => [ 'default' => '', @@ -131,7 +131,7 @@ public static function init(): self { * @param mixed $new_value The new value. * @param mixed $old_value The old value. * - * @return array|null + * @return array|null */ public function pre_update_option( $new_value, $old_value ): ?array { if ( ! is_array( $new_value ) || ! is_array( $old_value ) ) { @@ -143,7 +143,7 @@ public function pre_update_option( $new_value, $old_value ): ?array { /** * The default options. * - * @return array + * @return array */ public static function get_defaults(): array { @@ -216,7 +216,7 @@ public function is_const_enabled(): bool { * @param string $group The option group. * @param string $key The option key. * - * @return array|null + * @return array|null */ protected function get_default_key_value( string $group, string $key ): ?array { $defaults = $this->get_defaults(); @@ -254,9 +254,9 @@ public function is_const_defined( string $group, string $key ): bool { /** * Set plugin options. * - * @param array $options Plugin options. - * @param bool $first_install Add option on first install. - * @param bool $overwrite_existing Overwrite existing settings or merge. + * @param array $options Plugin options. + * @param bool $first_install Add option on first install. + * @param bool $overwrite_existing Overwrite existing settings or merge. */ public function set( array $options, bool $first_install = false, bool $overwrite_existing = true ): void { @@ -284,9 +284,9 @@ public function set( array $options, bool $first_install = false, bool $overwrit /** * Process the generic plugin options. * - * @param array $options The options array. + * @param array $options The options array. * - * @return array + * @return array */ private function process_generic_options( array $options ): array { @@ -313,7 +313,7 @@ private function process_generic_options( array $options ): array { /** * Merge recursively, including a proper substitution of values in sub-arrays when keys are the same. * - * @return array + * @return array */ public static function array_merge_recursive(): array { @@ -359,7 +359,7 @@ public static function array_merge_recursive(): array { /** * Get all the options, but without stripping the slashes. * - * @return array + * @return array */ public function get_all_raw(): array {