Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 4, 2022
1 parent 985b763 commit 3e96bf4
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Forms/ResultConditionsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ResourceFilter/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
2 changes: 1 addition & 1 deletion src/Page/CKANRegistryPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ public function getBasePath(DataObject $holder = null)
}

$link = $holder->RelativeLink();
return Director::baseURL() . trim($link, '/');
return Director::baseURL() . trim((string) $link, '/');
}
}
6 changes: 3 additions & 3 deletions src/Service/APIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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');
Expand Down
10 changes: 5 additions & 5 deletions src/Service/ResourcePopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3e96bf4

Please sign in to comment.