diff --git a/src/Forms/ResultConditionsField.php b/src/Forms/ResultConditionsField.php index 15a9d95..c59ec21 100644 --- a/src/Forms/ResultConditionsField.php +++ b/src/Forms/ResultConditionsField.php @@ -43,7 +43,7 @@ public function Type() public function performReadonlyTransformation() { // If we have no value then defer to the parent that renders a "none" field - $value = trim($this->Value()); + $value = trim((string) $this->Value()); if (empty($value)) { return parent::performReadonlyTransformation(); } diff --git a/src/Model/ResourceFilter/Dropdown.php b/src/Model/ResourceFilter/Dropdown.php index b21100e..2faef39 100644 --- a/src/Model/ResourceFilter/Dropdown.php +++ b/src/Model/ResourceFilter/Dropdown.php @@ -56,7 +56,7 @@ public function getClientConfig() */ protected function getConfiguredOptions() { - $spec = json_decode($this->Options, true) ?: []; + $spec = json_decode((string) $this->Options, true) ?: []; if (!isset($spec['selectType'])) { return []; diff --git a/src/Page/CKANRegistryPageController.php b/src/Page/CKANRegistryPageController.php index 10c38e4..e608215 100644 --- a/src/Page/CKANRegistryPageController.php +++ b/src/Page/CKANRegistryPageController.php @@ -121,6 +121,6 @@ public function getBasePath(DataObject $holder = null) } $link = $holder->RelativeLink(); - return Director::baseURL() . trim($link, '/'); + return Director::baseURL() . trim((string) $link, '/'); } } diff --git a/src/Service/APIClient.php b/src/Service/APIClient.php index f747322..da99b2c 100644 --- a/src/Service/APIClient.php +++ b/src/Service/APIClient.php @@ -44,7 +44,7 @@ public function getData(Resource $resource, $action = 'datastore_search', $id = { $endpoint = sprintf( '%s/api/%s/action/%s?id=%s', - trim($resource->Endpoint, '/'), + trim((string) $resource->Endpoint, '/'), APIClientInterface::API_VERSION, $action, $resource->{$id} @@ -63,11 +63,11 @@ public function getData(Resource $resource, $action = 'datastore_search', $id = throw new RuntimeException('CKAN API is not available. Error code ' . $statusCode); } - if (!count(preg_grep('#application/json#', $response->getHeader('Content-Type')))) { + if (!count(preg_grep('#application/json#', $response->getHeader('Content-Type') ?: []) ?: [])) { throw new RuntimeException('CKAN API returns an invalid response: Content-Type is not JSON'); } - $responseBody = json_decode($response->getBody()->getContents(), true); + $responseBody = json_decode((string) $response->getBody()->getContents(), true); if (!$responseBody || !isset($responseBody['success']) || !$responseBody['success']) { throw new RuntimeException('CKAN API returns an invalid response: Responded as invalid'); diff --git a/src/Service/ResourcePopulator.php b/src/Service/ResourcePopulator.php index 19cb5fe..4556a52 100644 --- a/src/Service/ResourcePopulator.php +++ b/src/Service/ResourcePopulator.php @@ -116,18 +116,18 @@ protected function validateResource(Resource $resource) protected function parseName($id) { // Parse "camelCase" to "space case" - $name = strtolower(preg_replace('/(?<=[a-z\d])([A-Z])/', ' \1', $id)); + $name = strtolower((string) preg_replace('/(?<=[a-z\d])([A-Z])/', ' \1', $id ?: '')); // Swap out certain characters with spaces - $name = str_replace(['_', '-'], ' ', $name); + $name = str_replace(['_', '-'], ' ', $name ?: ''); // Remove some non-alphanumeric characters - $name = trim(preg_replace('/[^\/\w\s]/', '', $name)); + $name = trim((string) preg_replace('/[^\/\w\s]/', '', $name ?: '')); // Remove extra spaces around slashes - $name = str_replace(' / ', '/', $name); + $name = str_replace(' / ', '/', $name ?: ''); - return ucfirst($name); + return ucfirst((string) $name); } /** diff --git a/tests/php/Forms/GridField/GridFieldDetailForm/ResourceFieldItemRequestTest.php b/tests/php/Forms/GridField/GridFieldDetailForm/ResourceFieldItemRequestTest.php index 55f8ec4..923154b 100644 --- a/tests/php/Forms/GridField/GridFieldDetailForm/ResourceFieldItemRequestTest.php +++ b/tests/php/Forms/GridField/GridFieldDetailForm/ResourceFieldItemRequestTest.php @@ -143,7 +143,7 @@ protected function assertArrayEqualsInOrder($expected, $actual) '. Actual: ' . print_r($actual, true); foreach ($actual as $key => $value) { - $expectedKey = key($expected); + $expectedKey = key($expected ?: []); $expectedValue = array_shift($expected); $this->assertSame($expectedKey, $key, $message); $this->assertEquals($expectedValue, $value, $message);