From e15a57bde62976e3fa3b570c460f1d26f631e4bb Mon Sep 17 00:00:00 2001 From: Ari Pringle Date: Wed, 5 Feb 2020 16:35:17 -0700 Subject: [PATCH 1/4] address instances of sizeof() being called on a BareResource object --- src/Endpoints/Endpoint.php | 2 +- src/SubResources/CustomField.php | 37 +++++++++++++++++--------------- src/Webhooks.php | 4 ++-- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Endpoints/Endpoint.php b/src/Endpoints/Endpoint.php index 88c8c9b..7028730 100644 --- a/src/Endpoints/Endpoint.php +++ b/src/Endpoints/Endpoint.php @@ -142,7 +142,7 @@ public function search(array $params = [], int $size = 200, int $page = null) do { $results = $this->request('post', 'search', ['json' => $params]); $entries = array_merge($entries, is_object($results)? [$results] : $results); - } while ($allPages && sizeof($results) >= $safeLimit && ++$params['page_number']); + } while ($allPages && is_array($results) && sizeof($results) >= $safeLimit && ++$params['page_number']); return $entries; } diff --git a/src/SubResources/CustomField.php b/src/SubResources/CustomField.php index 8e7b83f..da4216f 100644 --- a/src/SubResources/CustomField.php +++ b/src/SubResources/CustomField.php @@ -42,26 +42,29 @@ public function __construct(string $idOrName, $value = null, $resource = null) $values = []; $field = CRM::fieldList('customFieldDefinition', $idOrName, true); - switch (sizeof($field)) { - case 1: - if (is_array($field)) { - $field = current($field); //gets the first entry directly - } - break; + if (is_array($field)) { + switch (sizeof($field)) { + case 1: + if (is_array($field)) { + $field = current($field); //gets the first entry directly + } + break; - case 0: - throw new InvalidArg("Custom Field not found: $idOrName"); + case 0: + throw new InvalidArg("Custom Field not found: $idOrName"); - default: //will only happen on string identifiers (name) - if ($resource) { - //returns the first item found with the resource name in the available list - $field = array_filter($field, function ($f) use ($resource) { - return in_array($resource, $f->available_on); - }); - } else { - throw new InvalidArg("There's more than one '$idOrName' field. To distinguish we need the resource name as well."); - } + default: //will only happen on string identifiers (name) + if ($resource) { + //returns the first item found with the resource name in the available list + $field = array_filter($field, function ($f) use ($resource) { + return in_array($resource, $f->available_on); + }); + } else { + throw new InvalidArg("There's more than one '$idOrName' field. To distinguish we need the resource name as well."); + } + } } + $this->custom_field_definition_id = $field->id; $this->name = $field->name; $this->type = $field->data_type; diff --git a/src/Webhooks.php b/src/Webhooks.php index b7e1010..2d705ca 100644 --- a/src/Webhooks.php +++ b/src/Webhooks.php @@ -112,7 +112,7 @@ public function create(string $endpoint, $event = self::EV_ALL) $response[] = $result->id; } - return (sizeof($response) == 1)? $response[0] : $response; + return (is_array($response) && sizeof($response) == 1) ? $response[0] : $response; } public function list(int $id = null): array @@ -139,4 +139,4 @@ public function delete(int ...$id) { return array_column($this->request('delete', $id), 'id'); } -} \ No newline at end of file +} From d4054ed4566885a20cfac736cb82e56b731c35fd Mon Sep 17 00:00:00 2001 From: Ari Pringle Date: Wed, 5 Feb 2020 17:06:19 -0700 Subject: [PATCH 2/4] add support for the 'Connect Field' field type which can have multiple values --- src/SubResources/CustomField.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/SubResources/CustomField.php b/src/SubResources/CustomField.php index da4216f..36a773d 100644 --- a/src/SubResources/CustomField.php +++ b/src/SubResources/CustomField.php @@ -45,9 +45,7 @@ public function __construct(string $idOrName, $value = null, $resource = null) if (is_array($field)) { switch (sizeof($field)) { case 1: - if (is_array($field)) { - $field = current($field); //gets the first entry directly - } + $field = current($field); //gets the first entry directly break; case 0: @@ -72,8 +70,8 @@ public function __construct(string $idOrName, $value = null, $resource = null) $this->options = $field->options ?? []; //validating $resource and options, if available - if (is_array($value) && $this->type != "MultiSelect") { - throw new InvalidArg("Invalid multiple values for field $name that is not a MultiSelect field."); + if (is_array($value) && $this->type != "MultiSelect" && $this->type != "Connect") { + throw new InvalidArg('Invalid multiple values for field ' . $field->name . ' that is not a supported field type (type: ' . $this->type . ')'); } if ($resource && !in_array($resource, $this->resources)) { @@ -107,7 +105,7 @@ public function __construct(string $idOrName, $value = null, $resource = null) } } - if ($this->type == "MultiSelect") { + if ($this->type == "MultiSelect" || $this->type == "Connect") { $this->value = $values; } else { $this->value = $values[0]; @@ -119,7 +117,7 @@ public function __construct(string $idOrName, $value = null, $resource = null) public function getValue() { if (count($this->options) > 0) { - if ($this->type == "MultiSelect") { + if ($this->type == "MultiSelect" || $this->type == "Connect") { $values = []; foreach ($this->value as $val) { $values[] = $this->options[$val]; From 9b7874ffb1d0461e53ac1010ccdbf682bca05256 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Tue, 10 Nov 2020 14:09:52 -0700 Subject: [PATCH 3/4] Capitalizing the "interfaces" directory to be PSR-4 compatible --- src/{interfaces => Interfaces}/Cache.php | 0 src/{interfaces => Interfaces}/Crypt.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{interfaces => Interfaces}/Cache.php (100%) rename src/{interfaces => Interfaces}/Crypt.php (100%) diff --git a/src/interfaces/Cache.php b/src/Interfaces/Cache.php similarity index 100% rename from src/interfaces/Cache.php rename to src/Interfaces/Cache.php diff --git a/src/interfaces/Crypt.php b/src/Interfaces/Crypt.php similarity index 100% rename from src/interfaces/Crypt.php rename to src/Interfaces/Crypt.php From 71d3714426ab380975b061e281c32a7e4578fe09 Mon Sep 17 00:00:00 2001 From: Jay Klehr Date: Thu, 2 Dec 2021 00:33:35 -0700 Subject: [PATCH 4/4] allowing php 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 24f95ad..6c3794b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "minimum-stability": "stable", "require": { - "php": "^7.0", + "php": "^7.0 || ^8.0", "guzzlehttp/guzzle": "^6.3", "doctrine/inflector": "^1.2" },