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 13, 2022
1 parent 11a563c commit 2b2bb8b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function start(StoreInterface $store): array
protected function generateSecret(): string
{
$length = $this->config()->get('secret_length');
return substr(trim(Base32::encodeUpper(random_bytes(64)), '='), 0, $length);
return substr(trim(Base32::encodeUpper(random_bytes(64)) ?? '', '='), 0, $length);
}

/**
Expand All @@ -92,7 +92,7 @@ protected function generateSecret(): string
*/
public function register(HTTPRequest $request, StoreInterface $store): Result
{
$data = json_decode($request->getBody(), true);
$data = json_decode($request->getBody() ?? '', true);
$result = $this->getTotp($store)->verify($data['code'] ?? '');
if (!$result) {
return Result::create(false, _t(__CLASS__ . '.INVALID_CODE', 'Provided code was not valid'));
Expand Down
2 changes: 1 addition & 1 deletion src/VerifyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function start(StoreInterface $store, RegisteredMethod $method): array

public function verify(HTTPRequest $request, StoreInterface $store, RegisteredMethod $registeredMethod): Result
{
$data = json_decode($request->getBody(), true);
$data = json_decode($request->getBody() ?? '', true);
if (!$this->getTotp($store)->verify($data['code'] ?? '')) {
return Result::create(false, _t(__CLASS__ . '.INVALID_CODE', 'Invalid code'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/src/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function iPressTheBackupCodesButton($button)
*/
private function pressMfaButton($section, $button)
{
$section = str_replace("'", "\\'", $section);
$button = str_replace("'", "\\'", $button);
$section = str_replace("'", "\\'", $section ?? '');
$button = str_replace("'", "\\'", $button ?? '');
$js = <<<JS
document.querySelectorAll('.registered-method-list-item').forEach(el => {
if (!el.innerHTML.includes('{$section}')) {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/RegisterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function testStart()

$this->assertTrue($result['enabled'], 'Method should be enabled');
$this->assertStringContainsString(
rawurlencode(SiteConfig::current_site_config()->Title),
rawurlencode(SiteConfig::current_site_config()->Title ?? ''),
$result['uri'],
'Site name should be stored in provisioning URI'
);
$this->assertStringContainsString(
rawurlencode($this->member->Email),
rawurlencode($this->member->Email ?? ''),
$result['uri'],
'Provisioning URI should contain user email'
);
Expand Down

0 comments on commit 2b2bb8b

Please sign in to comment.