Skip to content

Commit

Permalink
Update PHPStan level to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed May 13, 2024
1 parent 72a801f commit dca97c5
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
4 changes: 3 additions & 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: 1
level: 2
bootstrapFiles:
- bin/phpstan/constants.php
- vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php
Expand All @@ -15,3 +15,5 @@ parameters:
- '#edd[a-zA-Z0-9\\_]+ not found#'
- '#EDD[a-zA-Z0-9\\_]* not found#'
- '#Parameter \$[a-zA-Z0-9\\_]+ of method .* has invalid type EDD_[a-zA-Z0-9\\_]+\.#'
- '#unknown class EDD#'
- '#has invalid type EDD#'
11 changes: 9 additions & 2 deletions src/Admin/AbstractOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract protected function get_page_title(): string;
/**
* Get the parent slug of the admin page.
*
* @return string|null
* @return string
*/
abstract protected function get_parent_slug(): string;

Expand Down Expand Up @@ -161,7 +161,14 @@ abstract public function enqueue_page_assets( string $hook ): void;
* @param string $url The plugin URL.
* @param string $domain The translation domain.
*/
protected function enqueue_assets( string $page_slug, string $script_handle, string $path = GTMKIT_PATH, string $url = GTMKIT_URL, string $domain = 'gtm-kit' ) {
protected function enqueue_assets( string $page_slug, string $script_handle, string $path = '', string $url = '', string $domain = 'gtm-kit' ) {

if ( empty( $path ) ) {
$path = GTMKIT_PATH;
}
if ( empty( $url ) ) {
$url = GTMKIT_URL;
}

$deps_file = $path . 'assets/admin/' . $script_handle . '.asset.php';
$dependency = [];
Expand Down
10 changes: 6 additions & 4 deletions src/Admin/IntegrationsOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ public function localize_script( string $page_slug, string $script_handle ): voi
$taxonomy_options = [];

foreach ( $taxonomies as $taxonomy ) {
$taxonomy_options[] = [
'label' => $taxonomy->label,
'value' => $taxonomy->name,
];
if ( is_object( $taxonomy ) && property_exists( $taxonomy, 'label' ) && property_exists( $taxonomy, 'name' ) ) {
$taxonomy_options[] = [
'label' => $taxonomy->label,
'value' => $taxonomy->name,
];
}
}

$admin_url = is_network_admin() ? network_admin_url() : admin_url();
Expand Down
9 changes: 8 additions & 1 deletion src/Common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ final class Util {
* @param string $path The plugin path.
* @param string $url The plugin URL.
*/
public function __construct( Options $options, RestAPIServer $rest_api_server, string $path = GTMKIT_PATH, string $url = GTMKIT_URL ) {
public function __construct( Options $options, RestAPIServer $rest_api_server, string $path = '', string $url = '' ) {
if ( empty( $path ) ) {
$path = GTMKIT_PATH;
}
if ( empty( $url ) ) {
$url = GTMKIT_URL;
}

$this->options = $options;
$this->rest_api_server = $rest_api_server;
$this->asset_path = $path . 'assets/';
Expand Down
4 changes: 4 additions & 0 deletions src/Integration/EasyDigitalDownloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ public function get_item_data( EDD_Download $download, array $options = [], arra
*/
public function include_customer_data( array $data_layer, $order ): array {

if ( ! ( $order instanceof Order ) ) {
return $data_layer;
}

$customer = new \EDD_Customer( $order->customer_id );
$payment_meta = edd_get_payment_meta( edd_get_purchase_id_by_key( $order->payment_key ) );
$address = $payment_meta['user_info']['address'];
Expand Down
43 changes: 23 additions & 20 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use WC_Coupon;
use WC_Customer;
use WC_Order;
use WC_Order_Item_Product;
use WC_Product;

/**
Expand Down Expand Up @@ -562,7 +563,7 @@ public function get_purchase_event( WC_Order $order, array $data_layer = [] ): a
$order_value = $order->get_total();
}

$shipping_total = $order->get_shipping_total();
$shipping_total = (float) $order->get_shipping_total();
if ( $this->options->get( 'integrations', 'woocommerce_exclude_shipping' ) ) {
$order_value -= $shipping_total;
}
Expand Down Expand Up @@ -1241,29 +1242,31 @@ private function get_order_items( WC_Order $order ): array {
if ( $items ) {
foreach ( $items as $item ) {

$product = $item->get_product();
$inc_tax = ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) );
$product_price = round( $order->get_item_total( $item, $inc_tax ), 2 );
if ( $item instanceof WC_Order_Item_Product ) {
$product = $item->get_product();
$inc_tax = ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) );
$product_price = round( $order->get_item_total( $item, $inc_tax ), 2 );

$additional_item_attributes = [
'quantity' => $item->get_quantity(),
'price' => $product_price,
];
$additional_item_attributes = [
'quantity' => $item->get_quantity(),
'price' => $product_price,
];

$coupon_discount = $this->get_coupon_discount( $coupons, $item->get_data() );
$coupon_discount = $this->get_coupon_discount( $coupons, $item->get_data() );

if ( $coupon_discount['coupon_codes'] ) {
$additional_item_attributes['coupon'] = implode( '|', array_filter( $coupon_discount['coupon_codes'] ) );
}
if ( $coupon_discount['discount'] ) {
$additional_item_attributes['discount'] = round( (float) $coupon_discount['discount'], 2 );
}
if ( $coupon_discount['coupon_codes'] ) {
$additional_item_attributes['coupon'] = implode( '|', array_filter( $coupon_discount['coupon_codes'] ) );
}
if ( $coupon_discount['discount'] ) {
$additional_item_attributes['discount'] = round( (float) $coupon_discount['discount'], 2 );
}

$order_items[] = $this->get_item_data(
$product,
$additional_item_attributes,
'purchase'
);
$order_items[] = $this->get_item_data(
$product,
$additional_item_attributes,
'purchase'
);
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php return array(
'root' => array(
'name' => 'tlamedia/gtm-kit',
'pretty_version' => 'dev-support',
'version' => 'dev-support',
'reference' => 'dfbedd763557cbcd7bcac30b5a630c0676c2e4d5',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '72a801fafdd619d9cba7ab0a990db0fe099b70bc',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev' => false,
),
'versions' => array(
'tlamedia/gtm-kit' => array(
'pretty_version' => 'dev-support',
'version' => 'dev-support',
'reference' => 'dfbedd763557cbcd7bcac30b5a630c0676c2e4d5',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '72a801fafdd619d9cba7ab0a990db0fe099b70bc',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit dca97c5

Please sign in to comment.