Skip to content

Commit 3f5eff7

Browse files
committed
Coding standards; assert tag saves in test
1 parent 2e76f98 commit 3f5eff7

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/ConvertKit_API.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function get_account()
152152

153153
/**
154154
* Gets all sequences
155-
*
155+
*
156156
* @see https://developers.convertkit.com/#list-sequences
157157
*
158158
* @return false|mixed
@@ -175,13 +175,18 @@ public function get_sequences()
175175
* @param string $first_name First Name.
176176
* @param array<string, string> $fields Custom Fields.
177177
* @param array<string, int> $tag_ids Tag ID(s) to subscribe to.
178-
*
178+
*
179179
* @see https://developers.convertkit.com/#add-subscriber-to-a-sequence
180180
*
181181
* @return false|mixed
182182
*/
183-
public function add_subscriber_to_sequence(int $sequence_id, string $email, string $first_name = '', array $fields = [], array $tag_ids = [])
184-
{
183+
public function add_subscriber_to_sequence(
184+
int $sequence_id,
185+
string $email,
186+
string $first_name = '',
187+
array $fields = [],
188+
array $tag_ids = []
189+
) {
185190
// Build parameters.
186191
$options = [
187192
'api_key' => $this->api_key,
@@ -194,7 +199,7 @@ public function add_subscriber_to_sequence(int $sequence_id, string $email, stri
194199
if (!empty($fields)) {
195200
$options['fields'] = $fields;
196201
}
197-
if (!empty($tags)) {
202+
if (!empty($tag_ids)) {
198203
$options['tags'] = $tag_ids;
199204
}
200205

@@ -212,7 +217,7 @@ public function add_subscriber_to_sequence(int $sequence_id, string $email, stri
212217
* @param string $sort_order Sort Order (asc|desc).
213218
* @param string $subscriber_state Subscriber State (active,cancelled).
214219
* @param integer $page Page.
215-
*
220+
*
216221
* @see https://developers.convertkit.com/#list-subscriptions-to-a-sequence
217222
*
218223
* @return false|mixed
@@ -222,14 +227,14 @@ public function get_sequence_subscriptions(
222227
string $sort_order = 'asc',
223228
string $subscriber_state = 'active',
224229
int $page = 1
225-
){
230+
) {
226231
return $this->get(
227232
sprintf('sequences/%s/subscriptions', $sequence_id),
228233
[
229-
'api_secret' => $this->api_secret,
230-
'sort_order' => $sort_order,
231-
'subscriber_state' => $subscriber_state,
232-
'page' => $page,
234+
'api_secret' => $this->api_secret,
235+
'sort_order' => $sort_order,
236+
'subscriber_state' => $subscriber_state,
237+
'page' => $page,
233238
]
234239
);
235240
}
@@ -720,8 +725,8 @@ private function strip_html_head_body_tags(string $markup)
720725
/**
721726
* Performs a GET request to the API.
722727
*
723-
* @param string $endpoint API Endpoint.
724-
* @param array<string, int|string> $args Request arguments.
728+
* @param string $endpoint API Endpoint.
729+
* @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
725730
*
726731
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
727732
*
@@ -739,8 +744,8 @@ public function get(string $endpoint, array $args = [])
739744
/**
740745
* Performs a POST request to the API.
741746
*
742-
* @param string $endpoint API Endpoint.
743-
* @param array<string, int|string> $args Request arguments.
747+
* @param string $endpoint API Endpoint.
748+
* @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
744749
*
745750
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
746751
*
@@ -758,8 +763,8 @@ public function post(string $endpoint, array $args = [])
758763
/**
759764
* Performs a PUT request to the API.
760765
*
761-
* @param string $endpoint API Endpoint.
762-
* @param array<string, int|string> $args Request arguments.
766+
* @param string $endpoint API Endpoint.
767+
* @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
763768
*
764769
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
765770
*
@@ -777,8 +782,8 @@ public function put(string $endpoint, array $args = [])
777782
/**
778783
* Performs a DELETE request to the API.
779784
*
780-
* @param string $endpoint API Endpoint.
781-
* @param array<string, int|string> $args Request arguments.
785+
* @param string $endpoint API Endpoint.
786+
* @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
782787
*
783788
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
784789
*
@@ -796,9 +801,9 @@ public function delete(string $endpoint, array $args = [])
796801
/**
797802
* Performs an API request using Guzzle.
798803
*
799-
* @param string $endpoint API Endpoint.
800-
* @param string $method Request method (POST, GET, PUT, PATCH, DELETE).
801-
* @param array<string, int|string> $args Request arguments.
804+
* @param string $endpoint API Endpoint.
805+
* @param string $method Request method.
806+
* @param array<string, int|string|array<string, int|string>|string> $args Request arguments.
802807
*
803808
* @throws \InvalidArgumentException If the provided arguments are not of the expected type.
804809
* @throws \Exception If JSON encoding arguments failed.

tests/ConvertKitAPITest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ public function testAddSubscriberToSequenceWithFirstName()
143143
{
144144
$emailAddress = $this->generateEmailAddress();
145145
$firstName = 'First Name';
146-
$result = $this->api->add_subscriber_to_sequence($_ENV['CONVERTKIT_API_SEQUENCE_ID'], $emailAddress, $firstName);
146+
$result = $this->api->add_subscriber_to_sequence(
147+
$_ENV['CONVERTKIT_API_SEQUENCE_ID'],
148+
$emailAddress,
149+
$firstName
150+
);
147151

148152
$this->assertInstanceOf('stdClass', $result);
149153
$this->assertArrayHasKey('subscription', get_object_vars($result));
@@ -208,7 +212,7 @@ public function testAddSubscriberToSequenceWithTagID()
208212

209213
// Fetch subscriber tags from API to confirm the tag saved.
210214
$subscriberTags = $this->api->get_subscriber_tags($result->subscription->subscriber->id);
211-
// @TODO.
215+
$this->assertEquals($subscriberTags->tags[0]->id, $_ENV['CONVERTKIT_API_TAG_ID']);
212216
}
213217

214218
/**

0 commit comments

Comments
 (0)