From c6698baddd397e7642741d5bc204457a7eea570c Mon Sep 17 00:00:00 2001 From: Jaime Perez Crespo <jaime.perez@uninett.no> Date: Tue, 4 Aug 2015 17:42:32 +0200 Subject: [PATCH] Resolve duplication of code. --- lib/SimpleSAML/Auth/Source.php | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/SimpleSAML/Auth/Source.php b/lib/SimpleSAML/Auth/Source.php index fef90b55d..4f071fa71 100644 --- a/lib/SimpleSAML/Auth/Source.php +++ b/lib/SimpleSAML/Auth/Source.php @@ -61,12 +61,7 @@ abstract class SimpleSAML_Auth_Source foreach ($sources as $id) { $source = $config->getArray($id); - if (!array_key_exists(0, $source) || !is_string($source[0])) { - throw new Exception( - 'Invalid authentication source \''.$id. - '\': First element must be a string which identifies the authentication source.' - ); - } + self::validateSource($source, $id); if ($source[0] !== $type) { continue; @@ -213,12 +208,7 @@ abstract class SimpleSAML_Auth_Source assert('is_string($authId)'); assert('is_array($config)'); - if (!array_key_exists(0, $config) || !is_string($config[0])) { - throw new Exception( - 'Invalid authentication source \''.$authId. - '\': First element must be a string which identifies the authentication source.' - ); - } + self::validateSource($config, $authId); $className = SimpleSAML_Module::resolveClass($config[0], 'Auth_Source', 'SimpleSAML_Auth_Source'); @@ -375,4 +365,23 @@ abstract class SimpleSAML_Auth_Source return $config->getOptions(); } + + + /** + * Make sure that the first element of an auth source is its identifier. + * + * @param array $source An array with the auth source configuration. + * @param string $id The auth source identifier. + * + * @throws Exception If the first element of $source is not an identifier for the auth source. + */ + protected static function validateSource($source, $id) + { + if (!array_key_exists(0, $source) || !is_string($source[0])) { + throw new Exception( + 'Invalid authentication source \''.$id. + '\': First element must be a string which identifies the authentication source.' + ); + } + } } -- GitLab