From e2fca5d3f80770dc6de809c0b612328d943767ff Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 5 Mar 2020 20:35:58 +0100 Subject: [PATCH] fixes Orange-Management/phpOMS#224 and fixes Orange-Management/phpOMS#212 --- Models/NullTag.php | 11 +++++++++++ Models/Tag.php | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Models/NullTag.php b/Models/NullTag.php index 0ef7d75..c71f9a9 100644 --- a/Models/NullTag.php +++ b/Models/NullTag.php @@ -24,4 +24,15 @@ namespace Modules\Tag\Models; */ final class NullTag extends Tag { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/Tag.php b/Models/Tag.php index 5b904b7..d75f38d 100644 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Tag\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; use phpOMS\Contract\ArrayableInterface; /** @@ -32,7 +34,7 @@ class Tag implements ArrayableInterface, \JsonSerializable * @var int * @since 1.0.0 */ - private int $id = 0; + protected int $id = 0; /** * Title. @@ -53,10 +55,10 @@ class Tag implements ArrayableInterface, \JsonSerializable /** * Creator. * - * @var null|int|\Modules\Admin\Models\Account + * @var Account * @since 1.0.0 */ - protected $owner = null; + protected Account $owner; /** * Tag type. @@ -69,25 +71,25 @@ class Tag implements ArrayableInterface, \JsonSerializable /** * Get created by * - * @return null|int|\Modules\Admin\Models\Account + * @return Account * * @since 1.0.0 */ - public function getOwner() + public function getOwner() : Account { - return $this->owner; + return $this->owner ?? new NullAccount(); } /** * Set created by * - * @param mixed $id Created by + * @param Account $id Created by * * @return void * * @since 1.0.0 */ - public function setOwner($id) : void + public function setOwner(Account $id) : void { $this->owner = $id; }