Skip to content

Commit

Permalink
Update PHPStan level to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed May 13, 2024
1 parent d1e1b56 commit 78bb8fe
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
9 changes: 4 additions & 5 deletions bin/phpstan/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_' );
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
parameters:
level: 4
level: 5
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- bin/phpstan/constants.php
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/IntegrationsOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'public' => true,
'_builtin' => false,
],
'object'
'objects'
);

$taxonomy_options = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function gtag(){<?php echo esc_attr( $this->datalayer_name ); ?>.push(arguments)
'functionality_storage': '<?php echo ( $this->options->get( 'general', 'gcm_functionality_storage' ) ) ? 'granted' : 'denied'; ?>',
'security_storage': '<?php echo ( $this->options->get( 'general', 'gcm_security_storage' ) ) ? 'granted' : 'denied'; ?>',
<?php if ( $this->options->get( 'general', 'gcm_wait_for_update' ) ) : ?>
'wait_for_update': <?php echo esc_html( (int) $this->options->get( 'general', 'gcm_wait_for_update' ) ); ?>
'wait_for_update': <?php echo esc_html( (string) ( (int) $this->options->get( 'general', 'gcm_wait_for_update' ) ) ); ?>
<?php endif; ?>
});
<?php echo ( $this->options->get( 'general', 'gcm_ads_data_redaction' ) ) ? 'gtag("set", "ads_data_redaction", true);' : ''; ?>
Expand Down
1 change: 0 additions & 1 deletion src/Installation/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Integration/EasyDigitalDownloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
13 changes: 7 additions & 6 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -881,7 +882,7 @@ public function get_item_data_tag( WC_Product $product, string $item_list_name,

return sprintf(
'<span class="gtmkit_product_data" style="display:none; visibility:hidden;" data-gtmkit_product_id="%s" data-gtmkit_product_data="%s"></span>',
esc_attr( $product->get_id() ),
esc_attr( (string) $product->get_id() ),
esc_attr( wp_json_encode( $item_data ) )
);
}
Expand Down

0 comments on commit 78bb8fe

Please sign in to comment.