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 #106

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
6 changes: 3 additions & 3 deletions src/Control/CwpBasicAuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function setWhitelistedIps($whitelistedIps)
if (!$ipList) {
continue;
}
$ips = array_map('trim', explode(',', $ipList));
$ips = array_map('trim', explode(',', $ipList ?? ''));
$whitelistedIps = array_merge($whitelistedIps, $ips);
}

// Return unique values with keys reset
$this->whitelistedIps = array_values(array_unique($whitelistedIps));
$this->whitelistedIps = array_values(array_unique($whitelistedIps ?? []));
return $this;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ protected function ipMatchesWhitelist()
}

$userIp = $_SERVER['REMOTE_ADDR'];
if (in_array($userIp, $whitelist)) {
if (in_array($userIp, $whitelist ?? [])) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Control/InitialisationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ protected function configureProxyDomainExclusions()

// Merge with exsiting if needed.
if (Environment::getEnv('NO_PROXY')) {
$noProxy = array_merge(explode(',', Environment::getEnv('NO_PROXY')), $noProxy);
$noProxy = array_merge(explode(',', Environment::getEnv('NO_PROXY') ?? ''), $noProxy);
}

/*
* Set the environment varial for NO_PROXY the same way the
* proxy variables are set above
*/
putenv('NO_PROXY=' . implode(',', array_unique($noProxy)));
putenv('NO_PROXY=' . implode(',', array_unique($noProxy ?? [])));
}
}
2 changes: 1 addition & 1 deletion src/Extension/CWPVersionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function getCWPVersionNumber()

// Example: "2.2.x-dev"
$cwpCore = $modules['cwp/cwp-core'];
return (string) substr($cwpCore, 0, strpos($cwpCore, '.', 2));
return (string) substr($cwpCore ?? '', 0, strpos($cwpCore ?? '', '.', 2));
}
}
2 changes: 1 addition & 1 deletion src/Extension/LoginAttemptNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function init()
$lastVisitedObj->setValue($sessionLastVisited);
$elapsed = $lastVisitedObj->TimeDiff();
$failures = $meantimeLoginAttempts->filter(['Status' => 'Failure'])->count();
$IPs = array_unique($meantimeLoginAttempts->column('IP'));
$IPs = array_unique($meantimeLoginAttempts->column('IP') ?? []);

if ($attempts == 1) {
$statusString = $failures ? "a failed" : "a successful";
Expand Down
12 changes: 6 additions & 6 deletions src/Extension/RichLinksExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public function RichLinks()
$content = $this->owner->value;

// Find all file links for processing.
preg_match_all('/<a.*href="\[file_link,id=([0-9]+)\].*".*>.*<\/a>/U', $content, $matches);
preg_match_all('/<a.*href="\[file_link,id=([0-9]+)\].*".*>.*<\/a>/U', $content ?? '', $matches);

// Attach the file type and size to each of the links.
for ($i = 0; $i < count($matches[0]); $i++) {
for ($i = 0; $i < count($matches[0] ?? []); $i++) {
$file = DataObject::get_by_id(File::class, $matches[1][$i]);
if ($file) {
$size = $file->getSize();
$ext = strtoupper($file->getExtension());
$ext = strtoupper($file->getExtension() ?? '');
// Replace the closing </a> tag with the size span (and reattach the closing tag).
$newLink = substr($matches[0][$i], 0, strlen($matches[0][$i]) - 4)
$newLink = substr($matches[0][$i] ?? '', 0, strlen($matches[0][$i] ?? '') - 4)
. "<span class='fileExt'> [$ext, $size]</span></a>";
$content = str_replace($matches[0][$i], $newLink, $content);
$content = str_replace($matches[0][$i] ?? '', $newLink ?? '', $content ?? '');
}
}

Expand All @@ -57,7 +57,7 @@ public function RichLinks()
'$1class="external" rel="external" $2<span class="nonvisual-indicator">(%s)</span>$3',
_t(__CLASS__ . '.ExternalLink', 'external link')
);
$content = preg_replace($pattern, $replacement, $content, -1);
$content = preg_replace($pattern ?? '', $replacement ?? '', $content ?? '', -1);

return $content;
}
Expand Down
7 changes: 6 additions & 1 deletion src/PasswordEncryptor/PBKDF2.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public function getIterations(): int

public function encrypt($password, $salt = null, $member = null)
{
return hash_pbkdf2($this->getAlgorithm(), (string) $password, (string) $salt, $this->getIterations());
return hash_pbkdf2(
$this->getAlgorithm() ?? '',
(string) $password,
(string) $salt,
$this->getIterations() ?? 0
);
}
}
2 changes: 1 addition & 1 deletion tests/PasswordEncryptor/PBKDF2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testEncrypt()
$result = $encryptor->encrypt('opensesame', $salt);
$this->assertSame(
'6bafcacb90',
substr($result, 0, 10),
substr($result ?? '', 0, 10),
'Hashed password with predictable salt did not match fixtured expectation'
);
}
Expand Down