Skip to content

Commit 71b91df

Browse files
committed
Migrate assertions to Webmozart
1 parent 423ec7d commit 71b91df

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

lib/Auth/Process/OTP2YubiPrefix.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace SimpleSAML\Module\authYubiKey\Auth\Process;
44

5+
use Webmozart\Assert\Assert;
6+
57
/*
68
* Copyright (C) 2009 Simon Josefsson <simon@yubico.com>.
79
*
@@ -56,8 +58,8 @@ class OTP2YubiPrefix extends \SimpleSAML\Auth\ProcessingFilter
5658
*/
5759
public function process(&$state)
5860
{
59-
assert(is_array($state));
60-
assert(array_key_exists('Attributes', $state));
61+
Assert::isArray($state);
62+
Assert::keyExists($state, 'Attributes');
6163
$attributes = $state['Attributes'];
6264

6365
\SimpleSAML\Logger::debug('OTP2YubiPrefix: enter with attributes: '.implode(',', array_keys($attributes)));

lib/Auth/Source/YubiKey.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace SimpleSAML\Module\authYubiKey\Auth\Source;
44

5+
use Webmozart\Assert\Assert;
6+
57
/*
68
* Copyright (C) 2009 Andreas Åkre Solberg <andreas.solberg@uninett.no>
79
* Copyright (C) 2009 Simon Josefsson <simon@yubico.com>.
@@ -78,8 +80,8 @@ class YubiKey extends \SimpleSAML\Auth\Source
7880
*/
7981
public function __construct($info, $config)
8082
{
81-
assert(is_array($info));
82-
assert(is_array($config));
83+
Assert::isArray($info);
84+
Assert::isArray($config);
8385

8486
// Call the parent constructor first, as required by the interface
8587
parent::__construct($info, $config);
@@ -105,7 +107,7 @@ public function __construct($info, $config)
105107
*/
106108
public function authenticate(&$state)
107109
{
108-
assert(is_array($state));
110+
Assert::isArray($state);
109111

110112
// We are going to need the authId in order to retrieve this authentication source later
111113
$state[self::AUTHID] = $this->authId;
@@ -130,14 +132,14 @@ public function authenticate(&$state)
130132
*/
131133
public static function handleLogin($authStateId, $otp)
132134
{
133-
assert(is_string($authStateId));
134-
assert(is_string($otp));
135+
Assert::string($authStateId);
136+
Assert::string($otp);
135137

136138
/* Retrieve the authentication state. */
137139
$state = \SimpleSAML\Auth\State::loadState($authStateId, self::STAGEID);
138140

139141
/* Find authentication source. */
140-
assert(array_key_exists(self::AUTHID, $state));
142+
Assert::keyExists($state, self::AUTHID);
141143
$source = \SimpleSAML\Auth\Source::getById($state[self::AUTHID]);
142144
if ($source === null) {
143145
throw new \Exception('Could not find authentication source with id '.$state[self::AUTHID]);
@@ -195,7 +197,7 @@ public static function getYubiKeyPrefix($otp)
195197
*/
196198
protected function login($otp)
197199
{
198-
assert(is_string($otp));
200+
Assert::string($otp);
199201

200202
require_once dirname(dirname(dirname(dirname(__FILE__)))).'/libextinc/Yubico.php';
201203

0 commit comments

Comments
 (0)