diff --git a/composer.json b/composer.json index e2c5048..9b46196 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "vlucas/phpdotenv": "^5.5", "phpunit/phpunit": "^5.7 || ^9.0", "squizlabs/php_codesniffer": "^3.3", - "phpstan/phpstan": "^1.2" + "phpstan/phpstan": "^2.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c3bd077..77033b3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,4 +6,4 @@ parameters: # Should not need to edit anything below here # Rule Level: https://phpstan.org/user-guide/rule-levels - level: 8 \ No newline at end of file + level: 10 \ No newline at end of file diff --git a/src/ConvertKit_API.php b/src/ConvertKit_API.php index 25c843a..6fcd9d3 100644 --- a/src/ConvertKit_API.php +++ b/src/ConvertKit_API.php @@ -177,7 +177,7 @@ public function get_oauth_url(string $redirectURI) * @param string $authCode Authorization Code, returned from get_oauth_url() flow. * @param string $redirectURI Redirect URI. * - * @return array API response + * @return mixed|array API response */ public function get_access_token(string $authCode, string $redirectURI) { @@ -215,7 +215,7 @@ public function get_access_token(string $authCode, string $redirectURI) * @param string $refreshToken Refresh Token. * @param string $redirectURI Redirect URI. * - * @return array API response + * @return mixed|array API response */ public function refresh_token(string $refreshToken, string $redirectURI) { @@ -338,7 +338,7 @@ public function get_resource(string $url) * * @throws \Exception If JSON encoding arguments failed. * - * @return false|mixed + * @return mixed|object */ public function request(string $endpoint, string $method, array $args = []) { diff --git a/src/ConvertKit_API_Traits.php b/src/ConvertKit_API_Traits.php index b5fc993..05773a3 100644 --- a/src/ConvertKit_API_Traits.php +++ b/src/ConvertKit_API_Traits.php @@ -161,7 +161,7 @@ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending = * * @see https://developers.convertkit.com/v4.html#convertkit-api-forms * - * @return false|array + * @return mixed|array */ public function get_forms( string $status = 'active', @@ -198,7 +198,7 @@ public function get_forms( * * @see https://developers.convertkit.com/v4.html#convertkit-api-forms * - * @return false|array + * @return mixed|array */ public function get_landing_pages( string $status = 'active', @@ -456,7 +456,7 @@ public function get_sequence_subscriptions( * * @see https://developers.convertkit.com/v4.html#list-tags * - * @return false|array + * @return mixed|array */ public function get_tags( bool $include_total_count = false, @@ -863,10 +863,26 @@ public function get_subscriber_id(string $email_address) ['email_address' => $email_address] ); + if (!$subscribers instanceof \stdClass) { + return false; + } + + if (!is_array($subscribers->subscribers)) { + return false; + } + if (!count($subscribers->subscribers)) { return false; } + if (!$subscribers->subscribers[0] instanceof \stdClass) { + return false; + } + + if (!is_int($subscribers->subscribers[0]->id)) { + return false; + } + // Return the subscriber's ID. return $subscribers->subscribers[0]->id; } @@ -878,7 +894,7 @@ public function get_subscriber_id(string $email_address) * * @see https://developers.convertkit.com/v4.html#get-a-subscriber * - * @return false|integer + * @return mixed|integer */ public function get_subscriber(int $subscriber_id) { @@ -895,7 +911,7 @@ public function get_subscriber(int $subscriber_id) * * @see https://developers.convertkit.com/v4.html#update-a-subscriber * - * @return false|mixed + * @return mixed */ public function update_subscriber( int $subscriber_id, @@ -930,7 +946,7 @@ public function update_subscriber( * * @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber * - * @return false|object + * @return mixed|object */ public function unsubscribe_by_email(string $email_address) { @@ -949,7 +965,7 @@ public function unsubscribe_by_email(string $email_address) * * @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber * - * @return false|object + * @return mixed|object */ public function unsubscribe(int $subscriber_id) { @@ -967,7 +983,7 @@ public function unsubscribe(int $subscriber_id) * * @see https://developers.convertkit.com/v4.html#list-tags-for-a-subscriber * - * @return false|array + * @return mixed|array */ public function get_subscriber_tags( int $subscriber_id, @@ -1044,7 +1060,7 @@ public function get_broadcasts( * * @see https://developers.convertkit.com/v4.html#create-a-broadcast * - * @return false|object + * @return mixed|object */ public function create_broadcast( string $subject = '', @@ -1103,7 +1119,7 @@ public function create_broadcast( * * @see https://developers.convertkit.com/v4.html#get-a-broadcast * - * @return false|object + * @return mixed|object */ public function get_broadcast(int $id) { @@ -1118,7 +1134,7 @@ public function get_broadcast(int $id) * * @see https://developers.convertkit.com/v4.html#get-stats * - * @return false|object + * @return mixed|object */ public function get_broadcast_stats(int $id) { @@ -1151,7 +1167,7 @@ public function get_broadcast_stats(int $id) * * @see https://developers.convertkit.com/#create-a-broadcast * - * @return false|object + * @return mixed|object */ public function update_broadcast( int $id, @@ -1213,7 +1229,7 @@ public function update_broadcast( * * @see https://developers.convertkit.com/v4.html#delete-a-broadcast * - * @return false|object + * @return mixed|object */ public function delete_broadcast(int $id) { @@ -1266,7 +1282,7 @@ public function get_webhooks( * * @throws \InvalidArgumentException If the event is not supported. * - * @return false|object + * @return mixed|object */ public function create_webhook(string $url, string $event, string $parameter = '') { @@ -1340,7 +1356,7 @@ public function create_webhook(string $url, string $event, string $parameter = ' * * @see https://developers.convertkit.com/v4.html#delete-a-webhook * - * @return false|object + * @return mixed|object */ public function delete_webhook(int $id) { @@ -1389,7 +1405,7 @@ public function get_custom_fields( * * @see https://developers.convertkit.com/v4.html#create-a-custom-field * - * @return false|object + * @return mixed|object */ public function create_custom_field(string $label) { @@ -1409,7 +1425,7 @@ public function create_custom_field(string $label) * * @see https://developers.convertkit.com/v4.html#bulk-create-custom-fields * - * @return false|object + * @return mixed|object */ public function create_custom_fields(array $labels, string $callback_url = '') { @@ -1444,7 +1460,7 @@ public function create_custom_fields(array $labels, string $callback_url = '') * * @see https://developers.convertkit.com/v4.html#update-a-custom-field * - * @return false|object + * @return mixed|object */ public function update_custom_field(int $id, string $label) { @@ -1463,7 +1479,7 @@ public function update_custom_field(int $id, string $label) * * @see https://developers.convertkit.com/#destroy-field * - * @return false|object + * @return mixed|object */ public function delete_custom_field(int $id) { @@ -1510,7 +1526,7 @@ public function get_purchases( * * @see https://developers.convertkit.com/v4.html#get-a-purchase * - * @return false|object + * @return mixed|object */ public function get_purchase(int $purchase_id) { @@ -1535,7 +1551,7 @@ public function get_purchase(int $purchase_id) * * @see https://developers.convertkit.com/v4.html#create-a-purchase * - * @return false|object + * @return mixed|object */ public function create_purchase( string $email_address,