Skip to content

Commit 44c63c0

Browse files
committed
Migrate assertions to Webmozart
1 parent 30c2030 commit 44c63c0

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

lib/Auth/Process/AttributeAddFromLDAP.php

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

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

5+
use Webmozart\Assert\Assert;
6+
57
/**
68
* Filter to add attributes to the identity by executing a query against an LDAP directory
79
*
@@ -140,8 +142,8 @@ public function __construct($config, $reserved)
140142
*/
141143
public function process(&$request)
142144
{
143-
assert(is_array($request));
144-
assert(array_key_exists('Attributes', $request));
145+
Assert::isArray($request);
146+
Assert::keyExists($request, 'Attributes');
145147

146148
$attributes = &$request['Attributes'];
147149

lib/Auth/Process/AttributeAddUsersGroups.php

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

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

5+
use Webmozart\Assert\Assert;
6+
57
/**
68
* Does a reverse membership lookup on the logged in user,
79
* looking for groups it is a member of and adds them to
@@ -24,8 +26,8 @@ class AttributeAddUsersGroups extends BaseFilter
2426
*/
2527
public function process(&$request)
2628
{
27-
assert(is_array($request));
28-
assert(array_key_exists('Attributes', $request));
29+
Assert::isArray($request);
30+
Assert::keyExists($request, 'Attributes');
2931

3032
// Log the process
3133
\SimpleSAML\Logger::debug(
@@ -226,10 +228,8 @@ protected function getGroupsActiveDirectory($attributes)
226228
* @param array $memberof
227229
* @return array
228230
*/
229-
protected function search($memberof)
231+
protected function search(array $memberof)
230232
{
231-
assert(is_array($memberof));
232-
233233
// Used to determine what DN's have already been searched
234234
static $searched = [];
235235

@@ -306,7 +306,7 @@ protected function search($memberof)
306306
*/
307307
protected function searchActiveDirectory($dn)
308308
{
309-
assert(is_string($dn) && $dn != '');
309+
Assert::stringNotEmpty($dn);
310310

311311
// Shorten the variable name
312312
$map = &$this->attribute_map;

lib/Auth/Source/LDAP.php

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

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

5+
use Webmozart\Assert\Assert;
6+
57
/**
68
* LDAP authentication source.
79
*
@@ -29,8 +31,8 @@ class LDAP extends \SimpleSAML\Module\core\Auth\UserPassBase
2931
*/
3032
public function __construct($info, $config)
3133
{
32-
assert(is_array($info));
33-
assert(is_array($config));
34+
Assert::isArray($info);
35+
Assert::isArray($config);
3436

3537
// Call the parent constructor first, as required by the interface
3638
parent::__construct($info, $config);
@@ -52,8 +54,8 @@ public function __construct($info, $config)
5254
*/
5355
protected function login($username, $password, array $sasl_args = null)
5456
{
55-
assert(is_string($username));
56-
assert(is_string($password));
57+
Assert::string($username);
58+
Assert::string($password);
5759

5860
return $this->ldapConfig->login($username, $password, $sasl_args);
5961
}

lib/Auth/Source/LDAPMulti.php

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

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

5+
use Webmozart\Assert\Assert;
6+
57
/**
68
* LDAP authentication source.
79
*
@@ -39,8 +41,8 @@ class LDAPMulti extends \SimpleSAML\Module\core\Auth\UserPassOrgBase
3941
*/
4042
public function __construct($info, $config)
4143
{
42-
assert(is_array($info));
43-
assert(is_array($config));
44+
Assert::isArray($info);
45+
assert::isArray($config);
4446

4547
// Call the parent constructor first, as required by the interface
4648
parent::__construct($info, $config);
@@ -99,9 +101,9 @@ public function __construct($info, $config)
99101
*/
100102
protected function login($username, $password, $org, array $sasl_args = null)
101103
{
102-
assert(is_string($username));
103-
assert(is_string($password));
104-
assert(is_string($org));
104+
Assert::string($username);
105+
Assert::string($password);
106+
Assert::string($org);
105107

106108
if (!array_key_exists($org, $this->ldapOrgs)) {
107109
// The user has selected an organization which doesn't exist anymore.

lib/ConfigHelper.php

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

33
namespace SimpleSAML\Module\ldap;
44

5+
use Webmozart\Assert\Assert;
6+
57
/**
68
* LDAP authentication source configuration parser.
79
*
@@ -122,10 +124,9 @@ class ConfigHelper
122124
* @param array $config Configuration.
123125
* @param string $location The location of this configuration. Used for error reporting.
124126
*/
125-
public function __construct($config, $location)
127+
public function __construct(array $config, $location)
126128
{
127-
assert(is_array($config));
128-
assert(is_string($location));
129+
Assert::string($location);
129130

130131
$this->location = $location;
131132

@@ -178,8 +179,8 @@ public function __construct($config, $location)
178179
*/
179180
public function login($username, $password, array $sasl_args = null)
180181
{
181-
assert(is_string($username));
182-
assert(is_string($password));
182+
Assert::string($username);
183+
Assert::string($password);
183184

184185
if (empty($password)) {
185186
\SimpleSAML\Logger::info($this->location.': Login with empty password disallowed.');

0 commit comments

Comments
 (0)