From e5610f01c559f9d66426457706b5f0d759f9f066 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 10 Jan 2016 19:15:05 +0100 Subject: [PATCH] Fixes during tests --- Account/Account.php | 34 ++++++++++++++++++++++++ Account/Group.php | 55 +++++++++++++++++++++------------------ Validation/Base/Email.php | 12 ++++----- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/Account/Account.php b/Account/Account.php index 20f2a0d94..c0904404a 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -17,6 +17,7 @@ namespace phpOMS\Account; use phpOMS\Localization\Localization; use phpOMS\Localization\NullLocalization; +use phpOMS\Validation\Base\Email; /** * Account manager class. @@ -98,6 +99,14 @@ class Account */ protected $lastActive = null; + /** + * Last activity. + * + * @var \DateTime + * @since 1.0.0 + */ + protected $created = null; + /** * Permissions. * @@ -284,6 +293,19 @@ class Account return $this->lastActive ?? new \DateTime('NOW'); } + /** + * Get last activity. + * + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreated() : \DateTime + { + return $this->created ?? new \DateTime('NOW'); + } + /** * Set name1. * @@ -341,6 +363,10 @@ class Account */ public function setEmail(\string $email) { + if(!Email::isValid($email)) { + throw new \InvalidArgumentException(); + } + $this->email = $email; } @@ -356,6 +382,10 @@ class Account */ public function setStatus(\int $status) { + if(!AccountStatus::isValidValue($status)) { + throw new \InvalidArgumentException(); + } + $this->status = $status; } @@ -371,6 +401,10 @@ class Account */ public function setType(\int $type) { + if(!AccountType::isValidValue($type)) { + throw new \InvalidArgumentException(); + } + $this->type = $type; } diff --git a/Account/Group.php b/Account/Group.php index 7f5e7b459..0f70f6bd9 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -77,14 +77,6 @@ class Group */ protected $permissions = []; - /** - * Multition cache. - * - * @var \Model\Account[] - * @since 1.0.0 - */ - private static $instances = []; - /** * Constructor. * @@ -96,35 +88,20 @@ class Group } /** - * Multition constructor. - * - * @param \int $id Account id - * - * @return \phpOMS\Account\Group - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function getInstance($id) - { - return self::$instances[$id] = self::$instances[$id] ?? new self(); - } - - /** - * Get account id. + * Get group id. * * @return \int * * @since 1.0.0 * @author Dennis Eichhorn */ - public function getId() + public function getId() : \int { return $this->id; } /** - * Get account name. + * Get group name. * * @return \string * @@ -149,4 +126,30 @@ class Group return $this->description; } + /** + * Set group name. + * + * @param \string $name Group name + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setName(\string $name) + { + $this->name = $name; + } + + /** + * Set group description. + * + * @param \string $description Group description + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setDescription(\string $description) + { + $this->description = $description; + } + } diff --git a/Validation/Base/Email.php b/Validation/Base/Email.php index d5f625115..e9429c3b5 100644 --- a/Validation/Base/Email.php +++ b/Validation/Base/Email.php @@ -13,9 +13,9 @@ * @version 1.0.0 * @link http://orange-management.com */ -namespace phpOMS\Validation; - +namespace phpOMS\Validation\Base; +use phpOMS\Validation\ValidatorAbstract; /** * Validator abstract. @@ -28,7 +28,7 @@ namespace phpOMS\Validation; * @link http://orange-management.com * @since 1.0.0 */ -abstract class Email extends ValidatorAbstract +class Email extends ValidatorAbstract { /** @@ -37,15 +37,15 @@ abstract class Email extends ValidatorAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct() + private function __construct() { } /** * {@inheritdoc} */ - public static function isValid($value) + public static function isValid(\string $value) : \bool { - return filter_var($value, FILTER_VALIDATE_EMAIL); + return filter_var($value, FILTER_VALIDATE_EMAIL) === false ? false : true; } }