From af2578c11b96c7d8289053efc0cfb22016e0077f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Tue, 16 Dec 2014 15:49:38 -0500
Subject: [PATCH] Code simplification.

---
 module/VuFind/src/VuFind/Auth/ILS.php | 35 ++++++++++-----------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/module/VuFind/src/VuFind/Auth/ILS.php b/module/VuFind/src/VuFind/Auth/ILS.php
index ec791ccfdc3..a01e02605fe 100644
--- a/module/VuFind/src/VuFind/Auth/ILS.php
+++ b/module/VuFind/src/VuFind/Auth/ILS.php
@@ -163,16 +163,13 @@ class ILS extends AbstractBase
     {
         // Ensure that all expected parameters are populated to avoid notices
         // in the code below.
-        $params = array(
-            'oldpwd' => '', 'password' => '', 'password2' => ''
-        );
-        foreach ($params as $param => $default) {
-            $params[$param] = $request->getPost()->get($param, $default);
+        $params = array();
+        foreach (array('oldpwd', 'password', 'password2') as $param) {
+            $params[$param] = $request->getPost()->get($param, '');
         }
 
         // Connect to catalog:
-        $patron = $this->authenticator->storedCatalogLogin();
-        if (!$patron) {
+        if (!($patron = $this->authenticator->storedCatalogLogin())) {
             throw new AuthException('authentication_error_technical');
         }
 
@@ -191,13 +188,8 @@ class ILS extends AbstractBase
         }
 
         // Update the user and send it back to the caller:
-        $table = $this->getUserTable();
-        $user = $table->getByUsername($patron['cat_username']);
-        $user['cat_password'] = $params['password'];
-        $user->saveCredentials(
-            !isset($user['cat_username']) ? " " : $user['cat_username'],
-            !isset($user['cat_password']) ? " " : $user['cat_password']
-        );
+        $user = $this->getUserTable()->getByUsername($patron['cat_username']);
+        $user->saveCredentials($patron['cat_username'], $params['password']);
         return $user;
     }
 
@@ -224,19 +216,18 @@ class ILS extends AbstractBase
         $user = $this->getUserTable()->getByUsername($info[$usernameField]);
 
         // No need to store the ILS password in VuFind's main password field:
-        $user->password = "";
+        $user->password = '';
 
         // Update user information based on ILS data:
-        $user->firstname = !isset($info['firstname']) ? " " : $info['firstname'];
-        $user->lastname = !isset($info['lastname']) ? " " : $info['lastname'];
-        $user->email = !isset($info['email']) ? " " : $info['email'];
-        $user->major = !isset($info['major']) ? " " : $info['major'];
-        $user->college = !isset($info['college']) ? " " : $info['college'];
+        $fields = array('firstname', 'lastname', 'email', 'major', 'college');
+        foreach ($fields as $field) {
+            $user->$field = isset($info[$field]) ? $info[$field] : ' ';
+        }
 
         // Update the user in the database, then return it to the caller:
         $user->saveCredentials(
-            !isset($info['cat_username']) ? " " : $info['cat_username'],
-            !isset($info['cat_password']) ? " " : $info['cat_password']
+            isset($info['cat_username']) ? $info['cat_username'] : ' ',
+            isset($info['cat_password']) ? $info['cat_password'] : ' '
         );
 
         return $user;
-- 
GitLab