Skip to content

Commit 0505045

Browse files
authored
Merge pull request #99 from Kit/tests-run-phpstan
Tests: Run PHPStan Static Analysis
2 parents 20c7bca + e59f342 commit 0505045

8 files changed

+583
-37
lines changed

.env.dist.testing

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONVERTKIT_API_BROADCAST_ID="8697158"
22
CONVERTKIT_API_FORM_ID="2765139"
3+
CONVERTKIT_API_FORM_ID_2="2780977"
34
CONVERTKIT_API_LEGACY_FORM_URL="https://app.convertkit.com/landing_pages/470099"
45
CONVERTKIT_API_LANDING_PAGE_URL="https://cheerful-architect-3237.ck.page/cc5eb21744"
56
CONVERTKIT_API_LEGACY_LANDING_PAGE_URL="https://app.convertkit.com/landing_pages/470103"

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CONVERTKIT_OAUTH_CLIENT_SECRET=
77
CONVERTKIT_OAUTH_REDIRECT_URI="https://convertkit-github.local/wp-admin/options-general.php?page=_wp_convertkit_settings"
88
CONVERTKIT_API_BROADCAST_ID="8697158"
99
CONVERTKIT_API_FORM_ID="2765139"
10+
CONVERTKIT_API_FORM_ID_2="2780977"
1011
CONVERTKIT_API_LEGACY_FORM_URL="https://app.convertkit.com/landing_pages/470099"
1112
CONVERTKIT_API_LANDING_PAGE_URL="https://cheerful-architect-3237.ck.page/cc5eb21744"
1213
CONVERTKIT_API_LEGACY_LANDING_PAGE_URL="https://app.convertkit.com/landing_pages/470103"

.github/workflows/tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
# Make sure your committed .env.dist.testing file ends with a newline.
4343
# The formatting of the contents to include a blank newline is deliberate.
4444
- name: Define GitHub Secrets in .env.dist.testing
45-
uses: DamianReeves/write-file-action@v1.1
45+
uses: DamianReeves/write-file-action@v1.3
4646
with:
4747
path: .env.dist.testing
4848
contents: |
@@ -68,6 +68,11 @@ jobs:
6868
- name: Build PHP Autoloader
6969
run: composer dump-autoload
7070

71+
# Run PHPStan for static analysis.
72+
- name: Run PHPStan Static Analysis
73+
working-directory: ${{ env.PLUGIN_DIR }}
74+
run: php vendor/bin/phpstan analyse --memory-limit=1250M
75+
7176
# Run Coding Standards.
7277
- name: Run Coding Standards
7378
run: php vendor/bin/phpcs --standard=phpcs.xml

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"vlucas/phpdotenv": "^5.5",
2424
"phpunit/phpunit": "^5.7 || ^9.0",
2525
"squizlabs/php_codesniffer": "^3.3",
26-
"phpstan/phpstan": "^1.2"
26+
"phpstan/phpstan": "^2.0"
2727
},
2828
"autoload": {
2929
"psr-4": {

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ parameters:
66

77
# Should not need to edit anything below here
88
# Rule Level: https://phpstan.org/user-guide/rule-levels
9-
level: 8
9+
level: 10

src/ConvertKit_API.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private function create_log(string $message)
142142
// Mask email addresses that may be contained within the message.
143143
$message = preg_replace_callback(
144144
'^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})^',
145+
// @phpstan-ignore-next-line - see https://github.com/phpstan/phpstan/issues/10396
145146
function ($matches) {
146147
return preg_replace('/\B[^@.]/', '*', $matches[0]);
147148
},
@@ -176,7 +177,7 @@ public function get_oauth_url(string $redirectURI)
176177
* @param string $authCode Authorization Code, returned from get_oauth_url() flow.
177178
* @param string $redirectURI Redirect URI.
178179
*
179-
* @return array<string, int|string> API response
180+
* @return mixed|array<string, int|string> API response
180181
*/
181182
public function get_access_token(string $authCode, string $redirectURI)
182183
{
@@ -214,7 +215,7 @@ public function get_access_token(string $authCode, string $redirectURI)
214215
* @param string $refreshToken Refresh Token.
215216
* @param string $redirectURI Redirect URI.
216217
*
217-
* @return array<string, int|string> API response
218+
* @return mixed|array<string, int|string> API response
218219
*/
219220
public function refresh_token(string $refreshToken, string $redirectURI)
220221
{
@@ -337,7 +338,7 @@ public function get_resource(string $url)
337338
*
338339
* @throws \Exception If JSON encoding arguments failed.
339340
*
340-
* @return false|mixed
341+
* @return mixed|object
341342
*/
342343
public function request(string $endpoint, string $method, array $args = [])
343344
{

src/ConvertKit_API_Traits.php

Lines changed: 89 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function get_growth_stats(\DateTime $starting = null, \DateTime $ending =
161161
*
162162
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
163163
*
164-
* @return false|array<int,\stdClass>
164+
* @return mixed|array<int,\stdClass>
165165
*/
166166
public function get_forms(
167167
string $status = 'active',
@@ -198,7 +198,7 @@ public function get_forms(
198198
*
199199
* @see https://developers.convertkit.com/v4.html#convertkit-api-forms
200200
*
201-
* @return false|array<int,\stdClass>
201+
* @return mixed|array<int,\stdClass>
202202
*/
203203
public function get_landing_pages(
204204
string $status = 'active',
@@ -222,21 +222,57 @@ public function get_landing_pages(
222222
);
223223
}
224224

225+
/**
226+
* Adds subscribers to forms in bulk.
227+
*
228+
* @param array<array<string,string>> $forms_subscribers_ids Array of arrays comprising of `form_id`, `subscriber_id` and optional `referrer` URL.
229+
* @param string $callback_url URL to notify for large batch size when async processing complete.
230+
*
231+
* @since 2.1.0
232+
*
233+
* @see https://developers.kit.com/v4.html#bulk-add-subscribers-to-forms
234+
*
235+
* @return false|object
236+
*/
237+
public function add_subscribers_to_forms(array $forms_subscribers_ids, string $callback_url = '')
238+
{
239+
// Build parameters.
240+
$options = ['additions' => $forms_subscribers_ids];
241+
if (!empty($callback_url)) {
242+
$options['callback_url'] = $callback_url;
243+
}
244+
245+
// Send request.
246+
return $this->post(
247+
'bulk/forms/subscribers',
248+
$options
249+
);
250+
}
251+
225252
/**
226253
* Adds a subscriber to a form by email address
227254
*
228255
* @param integer $form_id Form ID.
229256
* @param string $email_address Email Address.
257+
* @param string $referrer Referrer.
230258
*
231259
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form-by-email-address
232260
*
233261
* @return false|mixed
234262
*/
235-
public function add_subscriber_to_form_by_email(int $form_id, string $email_address)
263+
public function add_subscriber_to_form_by_email(int $form_id, string $email_address, string $referrer = '')
236264
{
265+
// Build parameters.
266+
$options = ['email_address' => $email_address];
267+
268+
if (!empty($referrer)) {
269+
$options['referrer'] = $referrer;
270+
}
271+
272+
// Send request.
237273
return $this->post(
238274
sprintf('forms/%s/subscribers', $form_id),
239-
['email_address' => $email_address]
275+
$options
240276
);
241277
}
242278

@@ -245,16 +281,28 @@ public function add_subscriber_to_form_by_email(int $form_id, string $email_addr
245281
*
246282
* @param integer $form_id Form ID.
247283
* @param integer $subscriber_id Subscriber ID.
284+
* @param string $referrer Referrer URL.
248285
*
249286
* @see https://developers.convertkit.com/v4.html#add-subscriber-to-form
250287
*
251288
* @since 2.0.0
252289
*
253290
* @return false|mixed
254291
*/
255-
public function add_subscriber_to_form(int $form_id, int $subscriber_id)
292+
public function add_subscriber_to_form(int $form_id, int $subscriber_id, string $referrer = '')
256293
{
257-
return $this->post(sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id));
294+
// Build parameters.
295+
$options = [];
296+
297+
if (!empty($referrer)) {
298+
$options['referrer'] = $referrer;
299+
}
300+
301+
// Send request.
302+
return $this->post(
303+
sprintf('forms/%s/subscribers/%s', $form_id, $subscriber_id),
304+
$options
305+
);
258306
}
259307

260308
/**
@@ -456,7 +504,7 @@ public function get_sequence_subscriptions(
456504
*
457505
* @see https://developers.convertkit.com/v4.html#list-tags
458506
*
459-
* @return false|array<int,\stdClass>
507+
* @return mixed|array<int,\stdClass>
460508
*/
461509
public function get_tags(
462510
bool $include_total_count = false,
@@ -863,10 +911,26 @@ public function get_subscriber_id(string $email_address)
863911
['email_address' => $email_address]
864912
);
865913

914+
if (!$subscribers instanceof \stdClass) {
915+
return false;
916+
}
917+
918+
if (!is_array($subscribers->subscribers)) {
919+
return false;
920+
}
921+
866922
if (!count($subscribers->subscribers)) {
867923
return false;
868924
}
869925

926+
if (!$subscribers->subscribers[0] instanceof \stdClass) {
927+
return false;
928+
}
929+
930+
if (!is_int($subscribers->subscribers[0]->id)) {
931+
return false;
932+
}
933+
870934
// Return the subscriber's ID.
871935
return $subscribers->subscribers[0]->id;
872936
}
@@ -878,7 +942,7 @@ public function get_subscriber_id(string $email_address)
878942
*
879943
* @see https://developers.convertkit.com/v4.html#get-a-subscriber
880944
*
881-
* @return false|integer
945+
* @return mixed|integer
882946
*/
883947
public function get_subscriber(int $subscriber_id)
884948
{
@@ -895,7 +959,7 @@ public function get_subscriber(int $subscriber_id)
895959
*
896960
* @see https://developers.convertkit.com/v4.html#update-a-subscriber
897961
*
898-
* @return false|mixed
962+
* @return mixed
899963
*/
900964
public function update_subscriber(
901965
int $subscriber_id,
@@ -930,7 +994,7 @@ public function update_subscriber(
930994
*
931995
* @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber
932996
*
933-
* @return false|object
997+
* @return mixed|object
934998
*/
935999
public function unsubscribe_by_email(string $email_address)
9361000
{
@@ -949,7 +1013,7 @@ public function unsubscribe_by_email(string $email_address)
9491013
*
9501014
* @see https://developers.convertkit.com/v4.html#unsubscribe-subscriber
9511015
*
952-
* @return false|object
1016+
* @return mixed|object
9531017
*/
9541018
public function unsubscribe(int $subscriber_id)
9551019
{
@@ -967,7 +1031,7 @@ public function unsubscribe(int $subscriber_id)
9671031
*
9681032
* @see https://developers.convertkit.com/v4.html#list-tags-for-a-subscriber
9691033
*
970-
* @return false|array<int,\stdClass>
1034+
* @return mixed|array<int,\stdClass>
9711035
*/
9721036
public function get_subscriber_tags(
9731037
int $subscriber_id,
@@ -1044,7 +1108,7 @@ public function get_broadcasts(
10441108
*
10451109
* @see https://developers.convertkit.com/v4.html#create-a-broadcast
10461110
*
1047-
* @return false|object
1111+
* @return mixed|object
10481112
*/
10491113
public function create_broadcast(
10501114
string $subject = '',
@@ -1103,7 +1167,7 @@ public function create_broadcast(
11031167
*
11041168
* @see https://developers.convertkit.com/v4.html#get-a-broadcast
11051169
*
1106-
* @return false|object
1170+
* @return mixed|object
11071171
*/
11081172
public function get_broadcast(int $id)
11091173
{
@@ -1118,7 +1182,7 @@ public function get_broadcast(int $id)
11181182
*
11191183
* @see https://developers.convertkit.com/v4.html#get-stats
11201184
*
1121-
* @return false|object
1185+
* @return mixed|object
11221186
*/
11231187
public function get_broadcast_stats(int $id)
11241188
{
@@ -1151,7 +1215,7 @@ public function get_broadcast_stats(int $id)
11511215
*
11521216
* @see https://developers.convertkit.com/#create-a-broadcast
11531217
*
1154-
* @return false|object
1218+
* @return mixed|object
11551219
*/
11561220
public function update_broadcast(
11571221
int $id,
@@ -1213,7 +1277,7 @@ public function update_broadcast(
12131277
*
12141278
* @see https://developers.convertkit.com/v4.html#delete-a-broadcast
12151279
*
1216-
* @return false|object
1280+
* @return mixed|object
12171281
*/
12181282
public function delete_broadcast(int $id)
12191283
{
@@ -1266,7 +1330,7 @@ public function get_webhooks(
12661330
*
12671331
* @throws \InvalidArgumentException If the event is not supported.
12681332
*
1269-
* @return false|object
1333+
* @return mixed|object
12701334
*/
12711335
public function create_webhook(string $url, string $event, string $parameter = '')
12721336
{
@@ -1340,7 +1404,7 @@ public function create_webhook(string $url, string $event, string $parameter = '
13401404
*
13411405
* @see https://developers.convertkit.com/v4.html#delete-a-webhook
13421406
*
1343-
* @return false|object
1407+
* @return mixed|object
13441408
*/
13451409
public function delete_webhook(int $id)
13461410
{
@@ -1389,7 +1453,7 @@ public function get_custom_fields(
13891453
*
13901454
* @see https://developers.convertkit.com/v4.html#create-a-custom-field
13911455
*
1392-
* @return false|object
1456+
* @return mixed|object
13931457
*/
13941458
public function create_custom_field(string $label)
13951459
{
@@ -1409,7 +1473,7 @@ public function create_custom_field(string $label)
14091473
*
14101474
* @see https://developers.convertkit.com/v4.html#bulk-create-custom-fields
14111475
*
1412-
* @return false|object
1476+
* @return mixed|object
14131477
*/
14141478
public function create_custom_fields(array $labels, string $callback_url = '')
14151479
{
@@ -1444,7 +1508,7 @@ public function create_custom_fields(array $labels, string $callback_url = '')
14441508
*
14451509
* @see https://developers.convertkit.com/v4.html#update-a-custom-field
14461510
*
1447-
* @return false|object
1511+
* @return mixed|object
14481512
*/
14491513
public function update_custom_field(int $id, string $label)
14501514
{
@@ -1463,7 +1527,7 @@ public function update_custom_field(int $id, string $label)
14631527
*
14641528
* @see https://developers.convertkit.com/#destroy-field
14651529
*
1466-
* @return false|object
1530+
* @return mixed|object
14671531
*/
14681532
public function delete_custom_field(int $id)
14691533
{
@@ -1510,7 +1574,7 @@ public function get_purchases(
15101574
*
15111575
* @see https://developers.convertkit.com/v4.html#get-a-purchase
15121576
*
1513-
* @return false|object
1577+
* @return mixed|object
15141578
*/
15151579
public function get_purchase(int $purchase_id)
15161580
{
@@ -1535,7 +1599,7 @@ public function get_purchase(int $purchase_id)
15351599
*
15361600
* @see https://developers.convertkit.com/v4.html#create-a-purchase
15371601
*
1538-
* @return false|object
1602+
* @return mixed|object
15391603
*/
15401604
public function create_purchase(
15411605
string $email_address,

0 commit comments

Comments
 (0)