diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 65be1c1..e369feb 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -130,5 +130,4 @@ jobs: # Run PHPStan for static analysis. - name: Run PHPStan Static Analysis working-directory: ${{ env.PLUGIN_DIR }} - if: ${{ contains('8.0 8.1 8.2 8.3 8.4', matrix.php-versions) }} run: php vendor/bin/phpstan analyse --memory-limit=1250M \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a129d07..396ca98 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,14 +6,17 @@ includes: # Parameters parameters: + # Analyse against the minimum supported PHP version. + # This flags features (union types, enums, str_contains, etc.) that would + # fail on older PHP versions regardless of which PHP version PHPStan runs on. + phpVersion: 70100 + # Paths to scan paths: - src/ # Paths to exclude - # API Traits are excluded as they are statically analysed in the Kit PHP SDK excludePaths: - - src/class-convertkit-api-traits.php - src/views/ # Location of WordPress Plugins for PHPStan to scan, building symbols. @@ -22,7 +25,6 @@ parameters: # Location of constants for PHPStan to scan, building symbols. scanFiles: - - src/class-convertkit-api-traits.php - /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress/wp-config.php # Don't report unmatched ignored errors on older PHP versions (7.2, 7.3) diff --git a/src/class-convertkit-api-traits.php b/src/class-convertkit-api-traits.php index 2c7f035..1244373 100644 --- a/src/class-convertkit-api-traits.php +++ b/src/class-convertkit-api-traits.php @@ -5,8 +5,6 @@ * @author ConvertKit */ -namespace ConvertKit_API; - /** * ConvertKit API Traits */ @@ -144,7 +142,7 @@ public function get_email_stats() * * @return false|mixed */ - public function get_growth_stats(\DateTime|null $starting = null, \DateTime|null $ending = null) + public function get_growth_stats(?\DateTime $starting = null, ?\DateTime $ending = null) { return $this->get( 'account/growth_stats', @@ -344,10 +342,10 @@ public function add_subscriber_to_legacy_form(int $form_id, int $subscriber_id) public function get_form_subscriptions( int $form_id, string $subscriber_state = 'active', - \DateTime|null $created_after = null, - \DateTime|null $created_before = null, - \DateTime|null $added_after = null, - \DateTime|null $added_before = null, + ?\DateTime $created_after = null, + ?\DateTime $created_before = null, + ?\DateTime $added_after = null, + ?\DateTime $added_before = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -471,10 +469,10 @@ public function add_subscriber_to_sequence(int $sequence_id, int $subscriber_id) public function get_sequence_subscriptions( int $sequence_id, string $subscriber_state = 'active', - \DateTime|null $created_after = null, - \DateTime|null $created_before = null, - \DateTime|null $added_after = null, - \DateTime|null $added_before = null, + ?\DateTime $created_after = null, + ?\DateTime $created_before = null, + ?\DateTime $added_after = null, + ?\DateTime $added_before = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -737,10 +735,10 @@ public function remove_tag_from_subscriber_by_email(int $tag_id, string $email_a public function get_tag_subscriptions( int $tag_id, string $subscriber_state = 'active', - \DateTime|null $created_after = null, - \DateTime|null $created_before = null, - \DateTime|null $tagged_after = null, - \DateTime|null $tagged_before = null, + ?\DateTime $created_after = null, + ?\DateTime $created_before = null, + ?\DateTime $tagged_after = null, + ?\DateTime $tagged_before = null, bool $include_total_count = false, string $after_cursor = '', string $before_cursor = '', @@ -836,10 +834,10 @@ public function get_email_templates( public function get_subscribers( string $subscriber_state = 'active', string $email_address = '', - \DateTime|null $created_after = null, - \DateTime|null $created_before = null, - \DateTime|null $updated_after = null, - \DateTime|null $updated_before = null, + ?\DateTime $created_after = null, + ?\DateTime $created_before = null, + ?\DateTime $updated_after = null, + ?\DateTime $updated_before = null, string $sort_field = 'id', string $sort_order = 'desc', bool $include_total_count = false, @@ -1265,8 +1263,8 @@ public function create_broadcast( string $content = '', string $description = '', bool $public = false, - \DateTime|null $published_at = null, - \DateTime|null $send_at = null, + ?\DateTime $published_at = null, + ?\DateTime $send_at = null, string $email_address = '', string $email_template_id = '', string $thumbnail_alt = '', @@ -1362,9 +1360,11 @@ public function get_broadcast_link_clicks( return $this->get( sprintf('broadcasts/%s/clicks', $id), $this->build_total_count_and_pagination_params( - after_cursor: $after_cursor, - before_cursor: $before_cursor, - per_page: $per_page + [], + false, + $after_cursor, + $before_cursor, + $per_page ) ); } @@ -1437,8 +1437,8 @@ public function update_broadcast( string $content = '', string $description = '', bool $public = false, - \DateTime|null $published_at = null, - \DateTime|null $send_at = null, + ?\DateTime $published_at = null, + ?\DateTime $send_at = null, string $email_address = '', string $email_template_id = '', string $thumbnail_alt = '', @@ -1841,14 +1841,14 @@ public function create_purchase( string $transaction_id, array $products, string $currency = 'USD', - string|null $first_name = null, - string|null $status = null, + ?string $first_name = null, + ?string $status = null, float $subtotal = 0, float $tax = 0, float $shipping = 0, float $discount = 0, float $total = 0, - \DateTime|null $transaction_time = null + ?\DateTime $transaction_time = null ) { // Build parameters. $options = [ diff --git a/src/class-convertkit-api-v4.php b/src/class-convertkit-api-v4.php index c105eee..ad3762a 100644 --- a/src/class-convertkit-api-v4.php +++ b/src/class-convertkit-api-v4.php @@ -14,7 +14,7 @@ */ class ConvertKit_API_V4 { - use ConvertKit_API\ConvertKit_API_Traits; + use ConvertKit_API_Traits; /** * The SDK version. diff --git a/src/class-convertkit-resource-v4.php b/src/class-convertkit-resource-v4.php index 60f9da0..95a9d2a 100644 --- a/src/class-convertkit-resource-v4.php +++ b/src/class-convertkit-resource-v4.php @@ -59,7 +59,7 @@ class ConvertKit_Resource_V4 { * * @var WP_Error|array|bool|null */ - public $resources = array(); + public $resources; /** * The key to use when alphabetically sorting resources.