From 800320ede5261998f61c5f2b2516b062312b7788 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 30 Jun 2026 22:17:15 +0200 Subject: [PATCH 1/2] fix(driver/pine): parenthesize nested ternaries for PHP 8 compatibility PHP 8 rejects unparenthesized `a ? b : c ? d : e`. Add explicit parens on the inner branch in _decode() and _encode() so the file parses. --- lib/Driver/Pine.php | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/Driver/Pine.php b/lib/Driver/Pine.php index 59f8e45..fc26da1 100644 --- a/lib/Driver/Pine.php +++ b/lib/Driver/Pine.php @@ -1,7 +1,7 @@ 'plain', 'show_encryption' => false, @@ -74,8 +74,8 @@ public function __construct(array $params = array()) 'use_new_passwd' => false, /* What host to look for on each line? */ - 'imaphost' => 'localhost' - ), $params)); + 'imaphost' => 'localhost', + ], $params)); } /** @@ -89,12 +89,12 @@ protected function _connect($user, $password) return; } - $params = array( + $params = [ 'username' => $user, 'password' => $password, 'hostspec' => $this->_params['host'], 'port' => $this->_params['port'], - ); + ]; try { $this->_ftp = Horde_Vfs::factory('ftp', $params); @@ -135,23 +135,23 @@ protected function _disconnect() */ protected function _decode($string) { - $list = array(); + $list = []; $lines = explode("\n", $string); for ($n = 0; $n < sizeof($lines); $n++) { $key = $n; $tmp = $lines[$n]; for ($i = 0; $i < strlen($tmp); $i++) { - if ((ord($tmp[$i]) >= self::FIRSTCH) && - (ord($tmp[$i]) <= self::LASTCH)) { + if ((ord($tmp[$i]) >= self::FIRSTCH) + && (ord($tmp[$i]) <= self::LASTCH)) { $xch = ord($tmp[$i]) - ($dti = $key); $xch += ($xch < self::FIRSTCH - self::TABSZ) ? 2 * self::TABSZ - : ($xch < self::FIRSTCH) ? self::TABSZ : 0; + : (($xch < self::FIRSTCH) ? self::TABSZ : 0); $dti = ($xch - self::FIRSTCH) + $dti; $dti -= ($dti >= 2 * self::TABSZ) ? 2 * self::TABSZ - : ($dti >= self::TABSZ) ? self::TABSZ : 0; + : (($dti >= self::TABSZ) ? self::TABSZ : 0); $key = $dti; $tmp[$i] = chr($xch); } @@ -194,12 +194,12 @@ protected function _encode($lines) $tmp = vsprintf("%.100s\t%.100s\t%.100s\t%d%s\n", $lines[$n]); for ($i = 0; $i < strlen($tmp); $i++) { $eti = $key; - if ((ord($tmp[$i]) >= self::FIRSTCH) && - (ord($tmp[$i]) <= self::LASTCH)) { + if ((ord($tmp[$i]) >= self::FIRSTCH) + && (ord($tmp[$i]) <= self::LASTCH)) { $eti += ord($tmp[$i]) - self::FIRSTCH; $eti -= ($eti >= 2 * self::TABSZ) ? 2 * self::TABSZ - : ($eti >= self::TABSZ) ? self::TABSZ : 0; + : (($eti >= self::TABSZ) ? self::TABSZ : 0); $key = $eti; $tmp[$i] = chr($eti + self::FIRSTCH); } @@ -232,9 +232,9 @@ protected function _lookup($user, $oldPassword) $this->_contents = $this->_decode($contents); foreach ($this->_contents as $line) { - if ($line[1] == $user && - (($line[2] == $this->_params['imaphost']) || - (!empty($line[4]) && $line[4] == $this->_params['imaphost']))) { + if ($line[1] == $user + && (($line[2] == $this->_params['imaphost']) + || (!empty($line[4]) && $line[4] == $this->_params['imaphost']))) { $this->_comparePasswords($line[0], $oldPassword); return; } @@ -254,10 +254,10 @@ protected function _lookup($user, $oldPassword) protected function _modify($user, $newPassword) { for ($i = 0; $i < sizeof($this->_contents); $i++) { - if ($this->_contents[$i][1] == $user && - (($this->_contents[$i][2] == $this->_params['imaphost']) || - (!empty($this->_contents[$i][4]) && - $this->_contents[$i][4] == $this->_params['imaphost']))) { + if ($this->_contents[$i][1] == $user + && (($this->_contents[$i][2] == $this->_params['imaphost']) + || (!empty($this->_contents[$i][4]) + && $this->_contents[$i][4] == $this->_params['imaphost']))) { $this->_contents[$i][0] = $newPassword; } } From 51d2d211abfe51a2869c6c85aaca8940549f857a Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 30 Jun 2026 22:17:21 +0200 Subject: [PATCH 2/2] style: apply horde-components qc --fix-qc-issues sweep php-cs-fixer rewrite across 33 files and .horde.yml: array() => [], list() => [], trailing commas, copyright bumps, compact YAML authors form, added keywords field. No logic changes. --- .horde.yml | 7 ++-- lib/Application.php | 6 +-- lib/Basic.php | 53 +++++++++++++++---------- lib/Driver.php | 13 ++++-- lib/Driver/Adsi.php | 2 +- lib/Driver/Composite.php | 10 ++--- lib/Driver/Expect.php | 8 ++-- lib/Driver/Expectpecl.php | 16 ++++---- lib/Driver/Horde.php | 10 ++--- lib/Driver/Http.php | 8 ++-- lib/Driver/Ispconfig.php | 18 ++++----- lib/Driver/Kolab.php | 6 +-- lib/Driver/Ldap.php | 52 ++++++++++++------------ lib/Driver/Null.php | 6 +-- lib/Driver/Poppassd.php | 12 +++--- lib/Driver/Procopen.php | 12 +++--- lib/Driver/Pspasswd.php | 16 ++++---- lib/Driver/Servuftp.php | 12 +++--- lib/Driver/Smbldap.php | 12 +++--- lib/Driver/Smbpasswd.php | 10 ++--- lib/Driver/Soap.php | 12 +++--- lib/Driver/Sql.php | 34 ++++++++-------- lib/Driver/Vmailmgr.php | 8 ++-- lib/Driver/Vpopmail.php | 28 ++++++------- lib/Exception.php | 6 +-- lib/Factory/Driver.php | 20 +++++----- lib/Test.php | 45 ++++++++++----------- src/Passwd.php | 5 +-- src/ResponsivePasswordController.php | 8 ++-- templates/responsive-body.html.php | 2 +- test/Passwd/TestCase.php | 15 +++---- test/Passwd/Unit/Driver/SqlTest.php | 7 ++-- test/Passwd/Unit/Factory/DriverTest.php | 25 ++++++------ 33 files changed, 259 insertions(+), 245 deletions(-) diff --git a/.horde.yml b/.horde.yml index a2670ee..021331b 100644 --- a/.horde.yml +++ b/.horde.yml @@ -9,14 +9,12 @@ list: sork type: application homepage: https://www.horde.org/apps/passwd authors: - - - name: Jan Schneider + - name: Jan Schneider user: jan email: jan@horde.org active: true role: lead - - - name: Michael Slusarz + - name: Michael Slusarz user: slusarz email: slusarz@horde.org active: false @@ -62,3 +60,4 @@ autoload: psr-4: Horde\Passwd\: /src vendor: horde +keywords: diff --git a/lib/Application.php b/lib/Application.php index 2893f87..7960702 100644 --- a/lib/Application.php +++ b/lib/Application.php @@ -1,7 +1,7 @@ _userid = $vars->get('userid', $this->_userid); } else { try { - $this->_userid = Horde::callHook('default_username', array(), 'passwd'); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::callHook() + * @deprecated Use $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook() instead + * @see Horde_Deprecated::callHook() + */ +$this->_userid = Horde::callHook('default_username', [], 'passwd'); } catch (Horde_Exception_HookNotSet $e) { } } @@ -84,7 +90,7 @@ public function render() public function status() { Horde::startBuffer(); - $GLOBALS['notification']->notify(array('listeners' => array('status'))); + $GLOBALS['notification']->notify(['listeners' => ['status']]); return Horde::endBuffer(); } @@ -121,15 +127,15 @@ private function _init() } } - $view = new Horde_View(array( - 'templatePath' => PASSWD_TEMPLATES - )); + $view = new Horde_View([ + 'templatePath' => PASSWD_TEMPLATES, + ]); $view->addHelper('FormTag'); $view->addHelper('Horde_Core_View_Helper_Help'); $view->addHelper('Horde_Core_View_Helper_Label'); $view->addHelper('Tag'); - $view->formInput = Horde_Util::formInput(); + $view->formInput = Util::formInput(); $view->url = $this->_vars->return_to ?: ''; $view->userid = $this->_userid ?: ''; $view->userChange = $conf['user']['change']; @@ -150,14 +156,14 @@ private function _init() $page_output->addScriptFile('stripe.js', 'horde'); $page_output->addScriptFile('passwd.js'); - $page_output->addInlineJsVars(array( - 'var Passwd' => array( + $page_output->addInlineJsVars([ + 'var Passwd' => [ 'current_pass' => _("Please provide your current password"), 'new_pass' => _("Please provide a new password"), 'verify_pass' => _("Please verify your new password"), 'no_match' => _("Your passwords do not match"), - ) - )); + ], + ]); $this->_output = $view->render('index'); } @@ -203,7 +209,7 @@ private function _changePassword($backend_key) $b_ptr = $this->_backends[$backend_key]; try { - Horde_Auth::checkPasswordPolicy($this->_vars->newpassword0, isset($b_ptr['policy']) ? $b_ptr['policy'] : array()); + Horde_Auth::checkPasswordPolicy($this->_vars->newpassword0, $b_ptr['policy'] ?? []); } catch (Horde_Auth_Exception $e) { $notification->push($e, 'horde.warning'); return; @@ -212,7 +218,7 @@ private function _changePassword($backend_key) // Do some simple strength tests, if enabled in the config file. if (!empty($conf['password']['strengthtests'])) { try { - Horde_Auth::checkPasswordSimilarity($this->_vars->newpassword0, array($this->_userid, $this->_vars->oldpassword)); + Horde_Auth::checkPasswordSimilarity($this->_vars->newpassword0, [$this->_userid, $this->_vars->oldpassword]); } catch (Horde_Auth_Exception $e) { $notification->push($e, 'horde.warning'); return; @@ -241,15 +247,20 @@ private function _changePassword($backend_key) $notification->push(sprintf(_("Password changed on %s."), $b_ptr['name']), 'horde.success'); try { - Horde::callHook('password_changed', array($this->_userid, $this->_vars->oldpassword, $this->_vars->newpassword0), 'passwd'); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::callHook() + * @deprecated Use $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook() instead + * @see Horde_Deprecated::callHook() + */ +Horde::callHook('password_changed', [$this->_userid, $this->_vars->oldpassword, $this->_vars->newpassword0], 'passwd'); } catch (Horde_Exception_HookNotSet $e) { } if (!empty($b_ptr['logout'])) { - $logout_url = $registry->getLogoutUrl(array( + $logout_url = $registry->getLogoutUrl([ 'msg' => _("Your password has been succesfully changed. You need to re-login to the system with your new password."), - 'reason' => Horde_Auth::REASON_MESSAGE - )); + 'reason' => Horde_Auth::REASON_MESSAGE, + ]); $registry->clearAuth(); $logout_url->redirect(); } @@ -280,15 +291,15 @@ private function _isPreferredBackend($backend) if (is_array($backend['preferred'])) { foreach ($backend['preferred'] as $backend) { if ( - $backend == $_SERVER['SERVER_NAME'] || - $backend == $_SERVER['HTTP_HOST'] + $backend == $_SERVER['SERVER_NAME'] + || $backend == $_SERVER['HTTP_HOST'] ) { return true; } } } elseif ( - $backend['preferred'] == $_SERVER['SERVER_NAME'] || - $backend['preferred'] == $_SERVER['HTTP_HOST'] + $backend['preferred'] == $_SERVER['SERVER_NAME'] + || $backend['preferred'] == $_SERVER['HTTP_HOST'] ) { return true; } diff --git a/lib/Driver.php b/lib/Driver.php index b976faa..89b827b 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -1,7 +1,7 @@ _params = $params; } @@ -107,7 +107,12 @@ protected function _encryptPassword($plaintext) public function changePassword($user, $oldpass, $newpass) { try { - $user = Horde::callHook('username', array($user, $this), 'passwd'); + /** + * ARCHITECTURE VIOLATION: Using deprecated Horde::callHook() + * @deprecated Use $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook() instead + * @see Horde_Deprecated::callHook() + */ +$user = Horde::callHook('username', [$user, $this], 'passwd'); } catch (Horde_Exception_HookNotSet $e) { } diff --git a/lib/Driver/Adsi.php b/lib/Driver/Adsi.php index 66fbd6e..448fea3 100644 --- a/lib/Driver/Adsi.php +++ b/lib/Driver/Adsi.php @@ -1,7 +1,7 @@ _params['drivers'] as $key => $val) { if (!isset($this->_drivers[$key])) { try { - $res = $driver->create($key, array_merge($val, array( - 'is_subdriver' => true - ))); + $res = $driver->create($key, array_merge($val, [ + 'is_subdriver' => true, + ])); } catch (Passwd_Exception $e) { throw new Passwd_Exception(sprintf(_("%s: unable to load sub driver: %s"), $key, $e->getMessage())); } diff --git a/lib/Driver/Expect.php b/lib/Driver/Expect.php index 576690e..e1e5d70 100644 --- a/lib/Driver/Expect.php +++ b/lib/Driver/Expect.php @@ -1,7 +1,7 @@ _params['program'] . - ' -f ' . escapeshellarg($this->_params['script']) . - ' -- ' . $this->_params['params'] . ' -log ' . escapeshellarg($log); + $prog = 'LANG=C LC_ALL=C ' . $this->_params['program'] + . ' -f ' . escapeshellarg($this->_params['script']) + . ' -- ' . $this->_params['params'] . ' -log ' . escapeshellarg($log); $exp = @popen($prog, 'w'); @fwrite($exp, $user . "\n"); diff --git a/lib/Driver/Expectpecl.php b/lib/Driver/Expectpecl.php index 3040ff7..5f5f975 100644 --- a/lib/Driver/Expectpecl.php +++ b/lib/Driver/Expectpecl.php @@ -1,7 +1,7 @@ _stream, array( - array( + $result = expect_expectl($this->_stream, [ + [ 0 => $expect, 1 => 'ok', - 2 => EXP_REGEXP - ) - )); + 2 => EXP_REGEXP, + ], + ]); switch ($result) { case EXP_EOF: @@ -80,7 +80,7 @@ protected function _changePassword($user, $oldpass, $newpass) } // Set up parameters - foreach (array('logfile', 'loguser', 'timeout') as $val) { + foreach (['logfile', 'loguser', 'timeout'] as $val) { if (isset($this->_params[$val])) { ini_set('expect.' . $val, $this->_params[$val]); } diff --git a/lib/Driver/Horde.php b/lib/Driver/Horde.php index aa70d69..80d369a 100644 --- a/lib/Driver/Horde.php +++ b/lib/Driver/Horde.php @@ -1,7 +1,7 @@ authenticate($user, array('password' => $oldpass, false))) { + if ($auth->authenticate($user, ['password' => $oldpass, false])) { /* Actually modify the password. */ - $auth->updateUser($user, $user, array( - 'password' => $newpass - )); + $auth->updateUser($user, $user, [ + 'password' => $newpass, + ]); } else { throw new Passwd_Exception(_("Incorrect old password.")); } diff --git a/lib/Driver/Http.php b/lib/Driver/Http.php index a26dde0..d8699a6 100644 --- a/lib/Driver/Http.php +++ b/lib/Driver/Http.php @@ -1,7 +1,7 @@ _params['username'] => $user, $this->_params['oldPasswd'] => $oldpass, $this->_params['passwd1'] => $newpass, - $this->_params['passwd2'] => $newpass - ), $this->_params['fields']); + $this->_params['passwd2'] => $newpass, + ], $this->_params['fields']); // Send the request try { diff --git a/lib/Driver/Ispconfig.php b/lib/Driver/Ispconfig.php index 9cfdf5a..f251c80 100644 --- a/lib/Driver/Ispconfig.php +++ b/lib/Driver/Ispconfig.php @@ -1,7 +1,7 @@ 'crypt-md5', 'show_encryption' => false, - ), $params)); + ], $params)); if (!class_exists('SoapClient')) { throw new Passwd_Exception('You need the soap PHP extension to use this driver.'); } - if (empty($this->_params['soap_uri']) || - empty($this->_params['soap_user'])) { + if (empty($this->_params['soap_uri']) + || empty($this->_params['soap_user'])) { throw new Passwd_Exception('The Passwd Ispconfig driver is not properly configured, edit your passwd/config/backends.local.php.'); } } @@ -49,9 +49,9 @@ protected function _changePassword($user, $oldpass, $newpass) { // Connect $soap_uri = $this->_params['soap_uri']; - $client = new SoapClient(null, array( + $client = new SoapClient(null, [ 'location' => $soap_uri . 'index.php', - 'uri' => $soap_uri)); + 'uri' => $soap_uri]); // Login try { @@ -71,7 +71,7 @@ protected function _changePassword($user, $oldpass, $newpass) try { $users = $client->mail_user_get( $session_id, - array('login' => $user) + ['login' => $user] ); } catch (SoapFault $e) { throw new Passwd_Exception($e); diff --git a/lib/Driver/Kolab.php b/lib/Driver/Kolab.php index 3bbd80e..c180fe4 100644 --- a/lib/Driver/Kolab.php +++ b/lib/Driver/Kolab.php @@ -1,7 +1,7 @@ _ldap = $params['ldap']; unset($params['ldap']); - parent::__construct(array_merge(array( + parent::__construct(array_merge([ 'host' => 'localhost', 'port' => 389, 'encryption' => 'crypt', @@ -70,11 +70,11 @@ public function __construct(array $params = array()) 'tls' => false, 'attribute' => 'userPassword', 'shadowlastchange' => '', - 'shadowmin' => '' - ), $params)); + 'shadowmin' => '', + ], $params)); - if (!empty($this->_params['tls']) && - empty($this->_params['sslhost'])) { + if (!empty($this->_params['tls']) + && empty($this->_params['sslhost'])) { $this->_params['sslhost'] = $this->_params['host']; } } @@ -112,7 +112,7 @@ protected function _changePassword($user, $oldpass, $newpass) $this->_userdn = $injector->getInstance('Horde_Core_Hooks')->callHook( 'userdn', 'passwd', - array($user) + [$user] ); } catch (Horde_Exception_HookNotSet $e) { // @todo Fix finding the user DN. @@ -147,35 +147,35 @@ protected function _changePassword($user, $oldpass, $newpass) } // Init the shadow policy array. - $lookupshadow = array( + $lookupshadow = [ 'shadowlastchange' => false, - 'shadowmin' => false - ); + 'shadowmin' => false, + ]; foreach (array_keys($lookupshadow) as $val) { - if (!empty($this->_params[$val]) && - $entry->exists($this->_params[$val])) { + if (!empty($this->_params[$val]) + && $entry->exists($this->_params[$val])) { $lookupshadow[$val] = $entry->getValue($this->_params[$val]); } } // Check if we may change the password. - if ($lookupshadow['shadowlastchange'] && - $lookupshadow['shadowmin'] && - (($lookupshadow['shadowlastchange'] + $lookupshadow['shadowmin']) > (time() / 86400))) { + if ($lookupshadow['shadowlastchange'] + && $lookupshadow['shadowmin'] + && (($lookupshadow['shadowlastchange'] + $lookupshadow['shadowmin']) > (time() / 86400))) { throw new Passwd_Exception(_("Minimum password age has not yet expired")); } // Change the user's password and update lastchange. try { - $entry->replace(array( - $this->_params['attribute'] => $this->_encryptPassword($newpass) - ), true); - - if (!empty($this->_params['shadowlastchange']) && - $lookupshadow['shadowlastchange']) { - $entry->replace(array( - $this->_params['shadowlastchange'] => floor(time() / 86400) - )); + $entry->replace([ + $this->_params['attribute'] => $this->_encryptPassword($newpass), + ], true); + + if (!empty($this->_params['shadowlastchange']) + && $lookupshadow['shadowlastchange']) { + $entry->replace([ + $this->_params['shadowlastchange'] => floor(time() / 86400), + ]); } $entry->update(); diff --git a/lib/Driver/Null.php b/lib/Driver/Null.php index 1b274f4..97b1738 100644 --- a/lib/Driver/Null.php +++ b/lib/Driver/Null.php @@ -1,7 +1,7 @@ 'localhost', - 'port' => 106 - ), $params)); + 'port' => 106, + ], $params)); } /** @@ -82,7 +82,7 @@ protected function _getPrompt() /* This should probably be a regex match for 2?0 or 3?0, no? */ $rc = substr($prompt, 0, 3); - if (!in_array($rc, array('200', '220', '250', '300'))) { + if (!in_array($rc, ['200', '220', '250', '300'])) { throw new Passwd_Exception($prompt); } } diff --git a/lib/Driver/Procopen.php b/lib/Driver/Procopen.php index a723d4b..5929ac6 100644 --- a/lib/Driver/Procopen.php +++ b/lib/Driver/Procopen.php @@ -1,7 +1,7 @@ array('pipe', 'r'), - 1 => array('pipe', 'w'), - 2 => array('pipe', 'w') - ); + $descr = [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; $output = ''; $process = @proc_open($this->_params['program'], $descr, $pipes); diff --git a/lib/Driver/Pspasswd.php b/lib/Driver/Pspasswd.php index e2786be..d679078 100644 --- a/lib/Driver/Pspasswd.php +++ b/lib/Driver/Pspasswd.php @@ -1,7 +1,7 @@ NUL 2>NUL'); - $cmdline = $this->_params['bin'] . ' \\\\' . $server . ' -u ' . $chpwd_adm . ' -p ' . $this->_params['admpwd'] . ' ' . $user. ' ' . $newpass; + $cmdline = $this->_params['bin'] . ' \\\\' . $server . ' -u ' . $chpwd_adm . ' -p ' . $this->_params['admpwd'] . ' ' . $user . ' ' . $newpass; exec($cmdline, $cmdreply, $retval); exec('NET USE \\\\' . $server . '\\IPC$ /D >NUL 2>NUL'); - if (strpos(implode(' ', $cmdreply), 'Password for ' . $server . '\\' . $user. ' successfully changed.') === false) { + if (strpos(implode(' ', $cmdreply), 'Password for ' . $server . '\\' . $user . ' successfully changed.') === false) { throw new Passwd_Exception(_("Access Denied.")); } } diff --git a/lib/Driver/Servuftp.php b/lib/Driver/Servuftp.php index 7acee24..6739867 100644 --- a/lib/Driver/Servuftp.php +++ b/lib/Driver/Servuftp.php @@ -1,7 +1,7 @@ 30 - ), $params)); + parent::__construct(array_merge([ + 'timeout' => 30, + ], $params)); } /** @@ -65,7 +65,7 @@ protected function _changePassword($user, $oldpass, $newpass) throw new Passwd_Exception(_("Incorrect password")); } - if ($this->_sendCommand('site pswd', '"' . $oldpass. '" "' . $newpass. '"') != self::PASSWORDOK) { + if ($this->_sendCommand('site pswd', '"' . $oldpass . '" "' . $newpass . '"') != self::PASSWORDOK) { $this->_disconnect(); throw new Passwd_Exception(_("Cannot change password")); } diff --git a/lib/Driver/Smbldap.php b/lib/Driver/Smbldap.php index 6d324da..86cf296 100644 --- a/lib/Driver/Smbldap.php +++ b/lib/Driver/Smbldap.php @@ -1,7 +1,7 @@ null, 'nt_attribute' => null, 'pw_set_attribute' => null, 'pw_expire_attribute' => null, 'pw_expire_time' => null, - 'smb_objectclass' => 'sambaSamAccount' - ), $params)); + 'smb_objectclass' => 'sambaSamAccount', + ], $params)); } /** @@ -73,7 +73,7 @@ protected function _changePassword($user, $oldpass, $newpass) // All changes must succeed or fail together. Attributes with // null name are not updated. - $changes = array(); + $changes = []; if (!is_null($this->_params['lm_attribute'])) { $changes[$this->_params['lm_attribute']] = $lmpasswd; } diff --git a/lib/Driver/Smbpasswd.php b/lib/Driver/Smbpasswd.php index f2853d6..6680aab 100644 --- a/lib/Driver/Smbpasswd.php +++ b/lib/Driver/Smbpasswd.php @@ -1,7 +1,7 @@ 'localhost', - 'program' => '/usr/bin/smbpasswd' - ), $params)); + 'program' => '/usr/bin/smbpasswd', + ], $params)); } /** diff --git a/lib/Driver/Soap.php b/lib/Driver/Soap.php index aeecd76..3a41e6f 100644 --- a/lib/Driver/Soap.php +++ b/lib/Driver/Soap.php @@ -1,7 +1,7 @@ _params['arguments'])) !== false) { $args[$pos] = $user; } diff --git a/lib/Driver/Sql.php b/lib/Driver/Sql.php index 718d5d0..fb5ff3b 100644 --- a/lib/Driver/Sql.php +++ b/lib/Driver/Sql.php @@ -1,7 +1,7 @@ _db = $params['db']; @@ -57,15 +57,15 @@ public function __construct(array $params = array()) } /* These default to matching the Auth_Sql defaults. */ - parent::__construct(array_merge(array( + parent::__construct(array_merge([ 'encryption' => 'ssha', 'pass_col' => 'user_pass', 'query_lookup' => false, 'query_modify' => false, 'show_encryption' => false, 'table' => 'horde_users', - 'user_col' => 'user_uid' - ), $params)); + 'user_col' => 'user_uid', + ], $params)); } /** @@ -79,12 +79,12 @@ public function __construct(array $params = array()) protected function _lookup($user, $oldpass) { if (!empty($this->_params['query_lookup'])) { - list($sql, $values) = $this->_parseQuery($this->_params['query_lookup'], $user, $oldpass); + [$sql, $values] = $this->_parseQuery($this->_params['query_lookup'], $user, $oldpass); } else { /* Build the SQL query. */ - $sql = 'SELECT ' . $this->_params['pass_col'] . ' FROM ' . $this->_params['table'] . - ' WHERE ' . $this->_params['user_col'] . ' = ?'; - $values = array($user); + $sql = 'SELECT ' . $this->_params['pass_col'] . ' FROM ' . $this->_params['table'] + . ' WHERE ' . $this->_params['user_col'] . ' = ?'; + $values = [$user]; } /* Run query. */ @@ -113,16 +113,16 @@ protected function _lookup($user, $oldpass) protected function _modify($user, $newpass) { if (!empty($this->_params['query_modify'])) { - list($sql, $values) = $this->_parseQuery($this->_params['query_modify'], $user, $newpass); + [$sql, $values] = $this->_parseQuery($this->_params['query_modify'], $user, $newpass); } else { /* Encrypt the password. */ $newpass = $this->_encryptPassword($newpass); /* Build the SQL query. */ - $sql = 'UPDATE ' . $this->_params['table'] . - ' SET ' . $this->_params['pass_col'] . ' = ?' . - ' WHERE ' . $this->_params['user_col'] . ' = ?'; - $values = array($newpass, $user); + $sql = 'UPDATE ' . $this->_params['table'] + . ' SET ' . $this->_params['pass_col'] . ' = ?' + . ' WHERE ' . $this->_params['user_col'] . ' = ?'; + $values = [$newpass, $user]; } /* Execute the query. */ @@ -147,9 +147,9 @@ protected function _modify($user, $newpass) protected function _parseQuery($string, $user, $password) { $query = ''; - $values = array(); + $values = []; $length = strlen($string); - @list($username, $domain) = explode('@', $user); + @[$username, $domain] = explode('@', $user); for ($i = 0; $i < $length; $i++) { if ($string[$i] == '%' && !empty($string[$i + 1])) { switch ($string[++$i]) { @@ -191,7 +191,7 @@ protected function _parseQuery($string, $user, $password) } } - return array($query, $values); + return [$query, $values]; } /** diff --git a/lib/Driver/Vmailmgr.php b/lib/Driver/Vmailmgr.php index 8137841..2e54653 100644 --- a/lib/Driver/Vmailmgr.php +++ b/lib/Driver/Vmailmgr.php @@ -1,7 +1,7 @@ _params['vmailinc']) && - is_readable($this->_params['vmailinc'])) { + if (isset($this->_params['vmailinc']) + && is_readable($this->_params['vmailinc'])) { include $this->_params['vmailinc']; } else { throw new Passwd_Exception('vmail.inc not found! (' . $this->_params['vmailinc'] . ')'); } - list($user, $domain) = explode('@', $user); + [$user, $domain] = explode('@', $user); $res = vchpass($domain, $oldpass, $user, $newpass); if ($res[0]) { diff --git a/lib/Driver/Vpopmail.php b/lib/Driver/Vpopmail.php index 9e2c253..db84617 100644 --- a/lib/Driver/Vpopmail.php +++ b/lib/Driver/Vpopmail.php @@ -1,7 +1,7 @@ 'pw_clear_passwd', 'domain' => 'pw_domain', 'encryption' => 'crypt', @@ -67,8 +67,8 @@ public function __construct($params = array()) 'passwd' => 'pw_passwd', 'show_encryption' => false, 'table' => 'horde_users', - 'use_clear_passwd' => false - ), + 'use_clear_passwd' => false, + ], $params )); } @@ -86,16 +86,16 @@ protected function _lookup($user, $oldpass) { /* Only split up username if domain is set in backend configuration. */ if (!empty($this->_params['domain'])) { - list($name, $domain) = explode('@', $user); + [$name, $domain] = explode('@', $user); } else { $name = $user; } /* Build the SQL query. */ - $sql = 'SELECT ' . $this->_params['passwd'] . - ' FROM ' . $this->_params['table'] . - ' WHERE ' . $this->_params['name'] . ' = ?'; - $values = array($name); + $sql = 'SELECT ' . $this->_params['passwd'] + . ' FROM ' . $this->_params['table'] + . ' WHERE ' . $this->_params['name'] . ' = ?'; + $values = [$name]; if ($this->_params['domain']) { $sql .= ' AND ' . $this->_params['domain'] . ' = ?'; $values[] = $domain; @@ -128,7 +128,7 @@ protected function _modify($user, $newpass) { /* Only split up username if domain is set in backend. */ if ($this->_params['domain']) { - list($name, $domain) = explode('@', $user); + [$name, $domain] = explode('@', $user); } else { $name = $user; } @@ -138,9 +138,9 @@ protected function _modify($user, $newpass) $newpass = $this->_encryptPassword($newpass); /* Build the SQL query. */ - $sql = 'UPDATE ' . $this->_params['table'] . - ' SET ' . $this->_params['passwd'] . ' = ?'; - $values = array($newpass); + $sql = 'UPDATE ' . $this->_params['table'] + . ' SET ' . $this->_params['passwd'] . ' = ?'; + $values = [$newpass]; if ($this->_params['use_clear_passwd']) { $sql .= ', ' . $this->_params['clear_passwd'] . ' = ?'; $values[] = $clear_password; diff --git a/lib/Exception.php b/lib/Exception.php index 9df15f8..c02529c 100644 --- a/lib/Exception.php +++ b/lib/Exception.php @@ -1,7 +1,7 @@ _loadBackends(); $backends = empty($params['is_subdriver']) ? $this->_backends - : array($name => $params); + : [$name => $params]; if (empty($backends[$name])) { throw new Passwd_Exception(sprintf(_("The password backend \"%s\" does not exist."), $name)); @@ -80,10 +80,10 @@ public function create($name, $params = array()) } if (empty($backend['params'])) { - $backend['params'] = array(); + $backend['params'] = []; } if (empty($backend['policy'])) { - $backend['policy'] = array(); + $backend['policy'] = []; } if (empty($params['is_subdriver']) && !empty($params)) { $backend['params'] = array_merge($backend['params'], $params); @@ -111,8 +111,8 @@ public function create($name, $params = array()) case 'Passwd_Driver_Sql': case 'Passwd_Driver_Vpopmail': - if (empty($backend['params']['db']) || - !($backend['params']['db'] instanceof Horde_Db_Adapter)) { + if (empty($backend['params']['db']) + || !($backend['params']['db'] instanceof Horde_Db_Adapter)) { try { if (empty($backend['params'])) { $backend['params']['db'] = $this->_injector @@ -187,12 +187,12 @@ protected function _loadBackends() throw new Passwd_Exception(_("No backends configured in backends.php")); } - $backends = array(); + $backends = []; foreach ($allbackends as $name => $backend) { if (empty($backend['disabled'])) { /* Make sure the 'params' entry exists. */ if (!isset($backend['params'])) { - $backend['params'] = array(); + $backend['params'] = []; } $backends[$name] = $backend; diff --git a/lib/Test.php b/lib/Test.php index 676c770..bb62a8f 100644 --- a/lib/Test.php +++ b/lib/Test.php @@ -1,7 +1,7 @@ 'Ctype Support', - 'ldap' => array( + 'ldap' => [ 'descrip' => 'LDAP Support', - 'error' => 'If you will be using the any of the LDAP drivers for password changes, PHP must have ldap support. Compile PHP --with-ldap before continuing.' - ), - 'mcrypt' => array( + 'error' => 'If you will be using the any of the LDAP drivers for password changes, PHP must have ldap support. Compile PHP --with-ldap before continuing.', + ], + 'mcrypt' => [ 'descrip' => 'Mcrypt Support', - 'error' => 'If you will be using the smbldap driver for password changes, PHP must have mcrypt support. Compile PHP --with-mcrypt before continuing.' - ), - 'soap' => array( + 'error' => 'If you will be using the smbldap driver for password changes, PHP must have mcrypt support. Compile PHP --with-mcrypt before continuing.', + ], + 'soap' => [ 'descrip' => 'SOAP Support', - 'error' => 'If you will be using the SOAP driver for password changes, PHP must have soap support. Compile PHP with --enable-soap before continuing.' - ) - ); + 'error' => 'If you will be using the SOAP driver for password changes, PHP must have soap support. Compile PHP with --enable-soap before continuing.', + ], + ]; /** * PHP settings list. * * @var array */ - protected $_settingsList = array(); + protected $_settingsList = []; /** * PEAR modules list. * * @var array */ - protected $_pearList = array( - 'Crypt_CHAP' => array( + protected $_pearList = [ + 'Crypt_CHAP' => [ 'path' => 'Crypt/CHAP.php', 'error' => 'If you will be using the smbldap driver for password changes, then you must install the PEAR Crypt_CHAP module.', 'required' => false, - ) - ); + ], + ]; /** */ @@ -70,9 +71,9 @@ public function __construct() { parent::__construct(); - $this->_fileList += array( - 'config/backends.php' => null - ); + $this->_fileList += [ + 'config/backends.php' => null, + ]; } /** @@ -80,7 +81,5 @@ public function __construct() * * @return string HTML output. */ - public function appTests() - { - } + public function appTests() {} } diff --git a/src/Passwd.php b/src/Passwd.php index b6447d6..2a7ceb3 100644 --- a/src/Passwd.php +++ b/src/Passwd.php @@ -1,4 +1,5 @@ \Horde_Util::formInput(), + 'formInput' => \Util::formInput(), 'url' => $vars->return_to ?: '', 'userid' => $registry->getAuth() ?: '', 'userChange' => $conf['user']['change'] ?? false, @@ -106,8 +108,8 @@ private function getStatusMessages(): string ); } - \Horde::startBuffer(); + Horde::startBuffer(); $notification->notify(['listeners' => ['responsive_status']]); - return \Horde::endBuffer(); + return Horde::endBuffer(); } } diff --git a/templates/responsive-body.html.php b/templates/responsive-body.html.php index 9a2f40a..67e4d0f 100644 --- a/templates/responsive-body.html.php +++ b/templates/responsive-body.html.php @@ -29,7 +29,7 @@ '' . htmlspecialchars($backends[$backend]['name']) . '' ); } - ?> + ?> diff --git a/test/Passwd/TestCase.php b/test/Passwd/TestCase.php index 461973e..8bb7bca 100644 --- a/test/Passwd/TestCase.php +++ b/test/Passwd/TestCase.php @@ -8,6 +8,7 @@ * @license http://www.horde.org/licenses/gpl GPL * @package Passwd * @subpackage UnitTests + * @coversNothing */ class Passwd_TestCase extends PHPUnit_Framework_TestCase { @@ -19,18 +20,18 @@ protected function getInjector() protected static function createBasicPasswdSetup(Horde_Test_Setup $setup) { $setup->setup( - array( - '_PARAMS' => array( + [ + '_PARAMS' => [ 'user' => 'test@example.com', - 'app' => 'passwd' - ), + 'app' => 'passwd', + ], 'Horde_Registry' => 'Registry', - ) + ] ); $setup->makeGlobal( - array( + [ 'registry' => 'Horde_Registry', - ) + ] ); } diff --git a/test/Passwd/Unit/Driver/SqlTest.php b/test/Passwd/Unit/Driver/SqlTest.php index e2b986c..a14404e 100644 --- a/test/Passwd/Unit/Driver/SqlTest.php +++ b/test/Passwd/Unit/Driver/SqlTest.php @@ -9,6 +9,7 @@ * @internal * @package Passwd * @subpackage UnitTests + * @coversNothing */ class Passwd_Unit_Driver_SqlTest extends Passwd_TestCase { @@ -24,10 +25,10 @@ public function setUp() { $GLOBALS['injector'] = $this->getInjector(); $factory = new Passwd_Factory_Driver($this->getInjector()); - $factory->backends = array(); + $factory->backends = []; // Get a Horde_Db_Adapter to prevent usage of Horde_Core_Factory_Db. - $db = new Horde_Db_Adapter_Pdo_Sqlite(array('dbname' => ':memory:')); + $db = new Horde_Db_Adapter_Pdo_Sqlite(['dbname' => ':memory:']); $db->execute("CREATE TABLE horde_users ( user_uid VARCHAR(255) PRIMARY KEY NOT NULL, user_pass VARCHAR(255) NOT NULL, @@ -35,7 +36,7 @@ public function setUp() user_hard_expiration_date INTEGER );"); - $this->driver = new Passwd_Driver_Sql(array('db' => $db)); + $this->driver = new Passwd_Driver_Sql(['db' => $db]); } public function testSetup() diff --git a/test/Passwd/Unit/Factory/DriverTest.php b/test/Passwd/Unit/Factory/DriverTest.php index 8ee198c..9bd863e 100644 --- a/test/Passwd/Unit/Factory/DriverTest.php +++ b/test/Passwd/Unit/Factory/DriverTest.php @@ -10,36 +10,37 @@ * @license http://www.horde.org/licenses/gpl GPL * @package Passwd * @subpackage UnitTests + * @coversNothing */ class Passwd_Unit_Factory_DriverTest extends Passwd_TestCase { - protected $_backends = array(); + protected $_backends = []; public function setUp() { $this->markTestIncomplete('Factories with configuration files don\'t work out of the box.'); - $this->_backends = array( - 'null' => array( + $this->_backends = [ + 'null' => [ 'disabled' => false, 'name' => 'Null', 'driver' => 'Null', - 'policy' => array( + 'policy' => [ 'minLength' => 6, - 'minNumeric' => 1 - ) - ) - ); + 'minNumeric' => 1, + ], + ], + ]; } public function testGettingSubdriversWorks() { $factory = new Passwd_Factory_Driver($this->getInjector()); - $factory->backends = array(); + $factory->backends = []; - $driver = $factory->create('Null', array( + $driver = $factory->create('Null', [ 'is_subdriver' => true, - 'driver' => 'Null' - )); + 'driver' => 'Null', + ]); $this->assertInstanceOf('Passwd_Driver', $driver); }