Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #177

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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