diff --git a/bin/phpstan/constants.php b/bin/phpstan/constants.php index e98fdd7..746aa5b 100644 --- a/bin/phpstan/constants.php +++ b/bin/phpstan/constants.php @@ -5,9 +5,8 @@ * @package GTM Kit */ -$gtmkit_file = dirname( __DIR__ ) . '/gtm-kit.php'; -define( 'GTMKIT_FILE', $gtmkit_file ); -define( 'GTMKIT_PATH', plugin_dir_path( GTMKIT_FILE ) ); -define( 'GTMKIT_BASENAME', plugin_basename( GTMKIT_FILE ) ); -define( 'GTMKIT_URL', plugin_dir_url( $gtmkit_file ) ); +define( 'GTMKIT_FILE', '/gtm-kit.php' ); +define( 'GTMKIT_PATH', '/' ); +define( 'GTMKIT_BASENAME', '/gtm-kit.php' ); +define( 'GTMKIT_URL', '/gtm-kit.php' ); define( 'GTMKIT_ADMIN_SLUG', 'gtmkit_' ); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7c82bd0..8518a6b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,7 @@ includes: - phar://phpstan.phar/conf/bleedingEdge.neon parameters: - level: 4 + level: 5 treatPhpDocTypesAsCertain: false bootstrapFiles: - bin/phpstan/constants.php diff --git a/src/Admin/IntegrationsOptionsPage.php b/src/Admin/IntegrationsOptionsPage.php index 185a590..3ddc280 100644 --- a/src/Admin/IntegrationsOptionsPage.php +++ b/src/Admin/IntegrationsOptionsPage.php @@ -86,7 +86,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi 'public' => true, '_builtin' => false, ], - 'object' + 'objects' ); $taxonomy_options = []; diff --git a/src/Common/Util.php b/src/Common/Util.php index 3f90577..b806712 100644 --- a/src/Common/Util.php +++ b/src/Common/Util.php @@ -148,12 +148,12 @@ private function set_site_data( array $data, array $options, string $wp_version, /** * Add shared data * - * @param array $data Current data. - * @param array $wp_version The WordPress version. + * @param array $data Current data. + * @param string $wp_version The WordPress version. * * @return array */ - private function add_shared_data( array $data, $wp_version ): array { + private function add_shared_data( array $data, string $wp_version ): array { $data['shared_data'] = [ 1 => [ 'label' => __( 'Server type:', 'gtm-kit' ), diff --git a/src/Frontend/Frontend.php b/src/Frontend/Frontend.php index 927bdcf..ce14da6 100644 --- a/src/Frontend/Frontend.php +++ b/src/Frontend/Frontend.php @@ -113,7 +113,7 @@ function gtag(){datalayer_name ); ?>.push(arguments) 'functionality_storage': 'options->get( 'general', 'gcm_functionality_storage' ) ) ? 'granted' : 'denied'; ?>', 'security_storage': 'options->get( 'general', 'gcm_security_storage' ) ) ? 'granted' : 'denied'; ?>', options->get( 'general', 'gcm_wait_for_update' ) ) : ?> - 'wait_for_update': options->get( 'general', 'gcm_wait_for_update' ) ); ?> + 'wait_for_update': options->get( 'general', 'gcm_wait_for_update' ) ) ); ?> }); options->get( 'general', 'gcm_ads_data_redaction' ) ) ? 'gtag("set", "ads_data_redaction", true);' : ''; ?> diff --git a/src/Installation/Activation.php b/src/Installation/Activation.php index 95710a4..e0f40f5 100644 --- a/src/Installation/Activation.php +++ b/src/Installation/Activation.php @@ -54,7 +54,6 @@ public function set_first_install_options(): void { // Add transient to trigger redirect to the Setup Wizard. \set_transient( 'gtmkit_activation_redirect', true, 30 ); \set_transient( 'gtmkit_first_install', true, 300 ); - add_action( 'admin_notices', [ $this, 'show_activation_notice' ] ); } /** diff --git a/src/Integration/EasyDigitalDownloads.php b/src/Integration/EasyDigitalDownloads.php index 2b57ecf..57cc5b4 100644 --- a/src/Integration/EasyDigitalDownloads.php +++ b/src/Integration/EasyDigitalDownloads.php @@ -322,7 +322,7 @@ public function get_datalayer_content_order_received( array $data_layer ): array if ( $this->options->get( 'general', 'debug_log' ) ) { error_log( 'GTM Kit: purchase event datalayer' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions - error_log( print_r( $data_layer, 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions + error_log( (string) print_r( $data_layer, true ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions } return apply_filters( 'gtmkit_datalayer_content_order_received', $data_layer ); diff --git a/src/Integration/WooCommerce.php b/src/Integration/WooCommerce.php index e14f50c..1d784e8 100644 --- a/src/Integration/WooCommerce.php +++ b/src/Integration/WooCommerce.php @@ -541,14 +541,14 @@ public function get_datalayer_content_order_received( array $data_layer ): array $data_layer = $this->include_customer_data( $data_layer, $order_value ); } - $order->add_meta_data( '_gtmkit_order_tracked', 1 ); + $order->add_meta_data( '_gtmkit_order_tracked', '1' ); $order->save(); return apply_filters( 'gtmkit_datalayer_content_order_received', $data_layer ); } /** - * Get the purchase event for the data layer + * Retrieves purchase event data for the data layer. * * @param WC_Order $order The order. * @param array $data_layer The datalayer content. @@ -568,15 +568,16 @@ public function get_purchase_event( WC_Order $order, array $data_layer = [] ): a $order_value -= $shipping_total; } - $data_layer['event'] = 'purchase'; - $data_layer['ecommerce'] = [ + $data_layer['event'] = 'purchase'; + $data_layer['ecommerce'] = [ 'transaction_id' => (string) $order->get_order_number(), 'value' => (float) $order_value, 'tax' => (float) $order->get_total_tax(), 'shipping' => (float) $shipping_total, 'currency' => $order->get_currency(), ]; - $data_layer['new_customer'] = ! DataStore::is_returning_customer( $order ); + /** @phpstan-ignore-next-line level5 */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort + $data_layer['new_customer'] = ! DataStore::is_returning_customer( $order ); // Param $order is declared as array but object is expected. $coupons = $order->get_coupon_codes(); @@ -881,7 +882,7 @@ public function get_item_data_tag( WC_Product $product, string $item_list_name, return sprintf( '', - esc_attr( $product->get_id() ), + esc_attr( (string) $product->get_id() ), esc_attr( wp_json_encode( $item_data ) ) ); }