Skip to content

Commit

Permalink
Merge pull request #177 from creative-commoners/pulls/2/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
emteknetnz authored Apr 26, 2022
2 parents 7bc6899 + b8fc56b commit 40b702d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Model/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Package extends DataObject
*/
public function getTitle()
{
return preg_replace('#^[^/]+/(silverstripe-)?#', '', $this->Name);
return preg_replace('#^[^/]+/(silverstripe-)?#', '', $this->Name ?? '');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function resolveCmsVersion()
];
$this->extend('updateVersionModules', $versionModules);

$records = $this->sourceRecords()->filter('Name', array_keys($versionModules));
$records = $this->sourceRecords()->filter('Name', array_keys($versionModules ?? []));
$versionParts = [];

foreach ($versionModules as $name => $label) {
Expand Down
10 changes: 5 additions & 5 deletions src/Tasks/UpdatePackageInfoTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function run($request)
$packages = $this->getPackageInfo($rawPackages);

// Get "name" from $packages and put into an array
$moduleNames = array_column($packages, 'Name');
$moduleNames = array_column($packages ?? [], 'Name');

$supportedPackages = $this->getSupportedPackages();
$moduleHealthInfo = $this->getHealthIndicator($moduleNames);
Expand All @@ -179,7 +179,7 @@ public function run($request)
foreach ($packages as $package) {
$packageName = $package['Name'];
if (is_array($supportedPackages)) {
$package['Supported'] = in_array($packageName, $supportedPackages);
$package['Supported'] = in_array($packageName, $supportedPackages ?? []);
}
if (is_array($moduleHealthInfo) && isset($moduleHealthInfo[$packageName])) {
$package['Rating'] = $moduleHealthInfo[$packageName];
Expand All @@ -202,12 +202,12 @@ public function getPackageInfo($packageList)
// Convert object to array, with Capitalised keys
$package = get_object_vars($package);
return array_combine(
array_map('ucfirst', array_keys($package)),
$package
array_map('ucfirst', array_keys($package ?? [])),
$package ?? []
);
};

$packageList = array_map($formatInfo, $packageList);
$packageList = array_map($formatInfo, $packageList ?? []);
$this->extend('updatePackageInfo', $packageList);
return $packageList;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Util/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function doRequest($endpoint, callable $callback)
throw new RuntimeException($failureMessage . 'Error code ' . $response->getStatusCode());
}

if (!in_array('application/json', $response->getHeader('Content-Type'))) {
if (!in_array('application/json', $response->getHeader('Content-Type') ?? [])) {
throw new RuntimeException($failureMessage . 'Response is not JSON');
}

Expand Down Expand Up @@ -176,8 +176,8 @@ protected function handleCacheFromResponse(Response $response, $result)
// Combine separate header rows
$cacheControl = implode(', ', $cacheControl);

if (strpos($cacheControl, 'no-store') === false
&& preg_match('/(?:max-age=)(\d+)/i', $cacheControl, $matches)
if (strpos($cacheControl ?? '', 'no-store') === false
&& preg_match('/(?:max-age=)(\d+)/i', $cacheControl ?? '', $matches)
) {
$duration = (int) $matches[1];

Expand Down
4 changes: 2 additions & 2 deletions src/Util/ComposerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function build()
throw new Exception('composer.json or composer.lock could not be found!');
}

$this->setJson(json_decode($composerJson));
$this->setLock(json_decode($composerLock));
$this->setJson(json_decode($composerJson ?? ''));
$this->setLock(json_decode($composerLock ?? ''));

$this->extend('onAfterBuild');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Util/ModuleHealthLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public function setModuleNames(array $moduleNames)

protected function getCacheKey()
{
return sha1(json_encode($this->getModuleNames()));
return sha1(json_encode($this->getModuleNames()) ?? '');
}
}
4 changes: 2 additions & 2 deletions tests/Model/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function testBadges()
// and that all our input is output
reset($badgeControlSample);
foreach ($badgeViewData as $badgeData) {
$title = key($badgeControlSample);
$type = current($badgeControlSample);
$title = key($badgeControlSample ?? []);
$type = current($badgeControlSample ?? []);
$this->assertSame(
[
'Title' => $title,
Expand Down

0 comments on commit 40b702d

Please sign in to comment.