From e6c57f029dfb9b8ccf80cf0c35867fbfb806601d Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Thu, 15 Aug 2013 14:58:08 +0200 Subject: [PATCH] Fix code styling to comply with coding standard refs #4503 --- .../Icinga/Application/DbAdapterFactory.php | 4 +- .../Authentication/Backend/DbUserBackend.php | 76 +++++++++++-------- library/Icinga/Util/ConfigAwareFactory.php | 1 - 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/library/Icinga/Application/DbAdapterFactory.php b/library/Icinga/Application/DbAdapterFactory.php index e834e72cc..0b98a3a0b 100644 --- a/library/Icinga/Application/DbAdapterFactory.php +++ b/library/Icinga/Application/DbAdapterFactory.php @@ -177,11 +177,9 @@ class DbAdapterFactory implements ConfigAwareFactory ); switch ($config->db) { case 'mysql': - return self::callFactory('Pdo_Mysql' ,$options); - + return self::callFactory('Pdo_Mysql', $options); case 'pgsql': return self::callFactory('Pdo_Pgsql', $options); - default: throw new ConfigurationError('Unsupported db type ' . $config->db . '.'); } diff --git a/library/Icinga/Authentication/Backend/DbUserBackend.php b/library/Icinga/Authentication/Backend/DbUserBackend.php index c06461997..43b9285b4 100644 --- a/library/Icinga/Authentication/Backend/DbUserBackend.php +++ b/library/Icinga/Authentication/Backend/DbUserBackend.php @@ -45,6 +45,28 @@ use \Icinga\Application\Logger; */ class DbUserBackend implements UserBackend { + /** + * Mapping of all table column names + */ + + const USER_NAME_COLUMN = 'user_name'; + + const FIRST_NAME_COLUMN = 'first_name'; + + const LAST_NAME_COLUMN = 'last_name'; + + const LAST_LOGIN_COLUMN = 'last_login'; + + const SALT_COLUMN = 'salt'; + + const PASSWORD_COLUMN = 'password'; + + const ACTIVE_COLUMN = 'active'; + + const DOMAIN_COLUMN = 'domain'; + + const EMAIL_COLUMN = 'email'; + /** * The database connection that will be used for fetching users * @@ -58,22 +80,6 @@ class DbUserBackend implements UserBackend * @var String */ private $userTable = "account"; - - /** - * Mapping of columns - * - * @var string - */ - private $USER_NAME_COLUMN = 'user_name', - $FIRST_NAME_COLUMN = 'first_name', - $LAST_NAME_COLUMN = 'last_name', - $LAST_LOGIN_COLUMN = 'last_login', - $SALT_COLUMN = 'salt', - $PASSWORD_COLUMN = 'password', - $ACTIVE_COLUMN = 'active', - $DOMAIN_COLUMN = 'domain', - $EMAIL_COLUMN = 'email'; - /** * Create a DbUserBackend * @@ -122,12 +128,15 @@ class DbUserBackend implements UserBackend $this->db->getConnection(); $res = $this->db ->select()->from($this->userTable) - ->where($this->USER_NAME_COLUMN.' = ?', $credential->getUsername()) - ->where($this->ACTIVE_COLUMN. ' = ?', true) + ->where(self::USER_NAME_COLUMN.' = ?', $credential->getUsername()) + ->where(self::ACTIVE_COLUMN. ' = ?', true) ->where( - $this->PASSWORD_COLUMN. ' = ?', hash_hmac('sha256', - $this->getUserSalt($credential->getUsername()), - $credential->getPassword()) + self::PASSWORD_COLUMN. ' = ?', + hash_hmac( + 'sha256', + $this->getUserSalt($credential->getUsername()), + $credential->getPassword() + ) ) ->query()->fetch(); if (!empty($res)) { @@ -148,9 +157,10 @@ class DbUserBackend implements UserBackend $this->db->update( $this->userTable, array( - $this->LAST_LOGIN_COLUMN => new \Zend_Db_Expr('NOW()') + self::LAST_LOGIN_COLUMN => new \Zend_Db_Expr('NOW()') ), - $this->USER_NAME_COLUMN.' = '.$this->db->quoteInto('?', $username)); + self::USER_NAME_COLUMN.' = '.$this->db->quoteInto('?', $username) + ); } /** @@ -164,10 +174,10 @@ class DbUserBackend implements UserBackend { $this->db->getConnection(); $res = $this->db->select() - ->from($this->userTable, $this->SALT_COLUMN) - ->where($this->USER_NAME_COLUMN.' = ?', $username) + ->from($this->userTable, self::SALT_COLUMN) + ->where(self::USER_NAME_COLUMN.' = ?', $username) ->query()->fetch(); - return $res[$this->SALT_COLUMN]; + return $res[self::SALT_COLUMN]; } /** @@ -187,8 +197,8 @@ class DbUserBackend implements UserBackend $this->db->getConnection(); $res = $this->db-> select()->from($this->userTable) - ->where($this->USER_NAME_COLUMN.' = ?',$username) - ->where($this->ACTIVE_COLUMN.' = ?',true) + ->where(self::USER_NAME_COLUMN.' = ?', $username) + ->where(self::ACTIVE_COLUMN.' = ?', true) ->query()->fetch(); if (empty($res)) { return null; @@ -210,12 +220,12 @@ class DbUserBackend implements UserBackend private function createUserFromResult(Array $result) { $usr = new User( - $result[$this->USER_NAME_COLUMN], - $result[$this->FIRST_NAME_COLUMN], - $result[$this->LAST_NAME_COLUMN], - $result[$this->EMAIL_COLUMN] + $result[self::USER_NAME_COLUMN], + $result[self::FIRST_NAME_COLUMN], + $result[self::LAST_NAME_COLUMN], + $result[self::EMAIL_COLUMN] ); - $usr->setDomain($result[$this->DOMAIN_COLUMN]); + $usr->setDomain($result[self::DOMAIN_COLUMN]); return $usr; } } diff --git a/library/Icinga/Util/ConfigAwareFactory.php b/library/Icinga/Util/ConfigAwareFactory.php index 2cbcc18a9..300118b33 100644 --- a/library/Icinga/Util/ConfigAwareFactory.php +++ b/library/Icinga/Util/ConfigAwareFactory.php @@ -41,4 +41,3 @@ interface ConfigAwareFactory */ public static function setConfig($config); } -