From 94c9c0bcd022afcc7193d291ba64e62592ea4ea0 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/NullWikiApp.php | 11 ++++++++++ Models/NullWikiCategory.php | 11 ++++++++++ Models/NullWikiDoc.php | 11 ++++++++++ Models/WikiCategory.php | 28 +++++++++++++------------- Models/WikiDoc.php | 40 +++++++++++++++++++------------------ 5 files changed, 68 insertions(+), 33 deletions(-) diff --git a/Models/NullWikiApp.php b/Models/NullWikiApp.php index 0ce4330..76ab718 100644 --- a/Models/NullWikiApp.php +++ b/Models/NullWikiApp.php @@ -24,4 +24,15 @@ namespace Modules\Knowledgebase\Models; */ final class NullWikiApp extends WikiApp { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/NullWikiCategory.php b/Models/NullWikiCategory.php index 74fcb4e..4a41d63 100644 --- a/Models/NullWikiCategory.php +++ b/Models/NullWikiCategory.php @@ -24,4 +24,15 @@ namespace Modules\Knowledgebase\Models; */ final class NullWikiCategory extends WikiCategory { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/NullWikiDoc.php b/Models/NullWikiDoc.php index 22aeb54..7e3cead 100644 --- a/Models/NullWikiDoc.php +++ b/Models/NullWikiDoc.php @@ -24,4 +24,15 @@ namespace Modules\Knowledgebase\Models; */ final class NullWikiDoc extends WikiDoc { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/WikiCategory.php b/Models/WikiCategory.php index 4c31cf0..c2d57bf 100644 --- a/Models/WikiCategory.php +++ b/Models/WikiCategory.php @@ -37,10 +37,10 @@ class WikiCategory implements \JsonSerializable * * There can be different wikis * - * @var null|int|WikiApp + * @var null|WikiApp * @since 1.0.0 */ - private $app = null; + private ?WikiApp $app = null; /** * Name. @@ -61,10 +61,10 @@ class WikiCategory implements \JsonSerializable /** * Parent category. * - * @var null|int|self + * @var self * @since 1.0.0 */ - private $parent = null; + private ?self $parent = null; /** * Get id. @@ -81,25 +81,25 @@ class WikiCategory implements \JsonSerializable /** * Get app * - * @return null|int|WikiApp + * @return WikiApp * * @since 1.0.0 */ - public function getApp() + public function getApp() : WikiApp { - return $this->app; + return $this->app ?? new NullWikiApp(); } /** * Set app * - * @param int $app App + * @param null|WikiApp $app App * * @return void * * @since 1.0.0 */ - public function setApp(int $app) : void + public function setApp(?WikiApp $app) : void { $this->app = $app; } @@ -159,25 +159,25 @@ class WikiCategory implements \JsonSerializable /** * Get parent category * - * @return null|int|self + * @return null|self * * @since 1.0.0 */ - public function getParent() + public function getParent() : self { - return $this->parent; + return $this->parent ?? new NullWikiCategory(); } /** * Set parent category * - * @param int $parent Parent category + * @param null|self $parent Parent category * * @return void * * @since 1.0.0 */ - public function setParent(int $parent) : void + public function setParent(?self $parent) : void { $this->parent = $parent; } diff --git a/Models/WikiDoc.php b/Models/WikiDoc.php index 4a88017..c1f5713 100644 --- a/Models/WikiDoc.php +++ b/Models/WikiDoc.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Knowledgebase\Models; +use Modules\Tag\Models\Tag; + /** * Wiki document class. * @@ -37,10 +39,10 @@ class WikiDoc implements \JsonSerializable * * There can be different wikis * - * @var null|int|WikiApp + * @var null|WikiApp * @since 1.0.0 */ - private $app = null; + private ?WikiApp $app = null; /** * Name. @@ -77,10 +79,10 @@ class WikiDoc implements \JsonSerializable /** * Category. * - * @var int|WikiCategory + * @var null|WikiCategory * @since 1.0.0 */ - private $category = 0; + private ?WikiCategory $category = null; /** * Language. @@ -88,15 +90,15 @@ class WikiDoc implements \JsonSerializable * @var string * @since 1.0.0 */ - private $language = 'en'; + private string $language = 'en'; /** * Tags. * - * @var array + * @var Tag[] * @since 1.0.0 */ - private $tags = []; + private array $tags = []; /** * Get id. @@ -113,25 +115,25 @@ class WikiDoc implements \JsonSerializable /** * Get app * - * @return null|int|WikiApp + * @return WikiApp * * @since 1.0.0 */ - public function getApp() + public function getApp() : WikiApp { - return $this->app; + return $this->app ?? new NullWikiApp(); } /** * Set app * - * @param int $app App + * @param null|WikiApp $app App * * @return void * * @since 1.0.0 */ - public function setApp(int $app) : void + public function setApp(?WikiApp $app) : void { $this->app = $app; } @@ -269,25 +271,25 @@ class WikiDoc implements \JsonSerializable /** * Get category * - * @return mixed + * @return WikiCategory * * @since 1.0.0 */ - public function getCategory() + public function getCategory() : WikiCategory { - return $this->category; + return $this->category ?? new NullWikiCategory(); } /** * Set cateogry * - * @param int $category Category + * @param null|WikiCategory $category Category * * @return void * * @since 1.0.0 */ - public function setCategory(int $category) : void + public function setCategory(?WikiCategory $category) : void { $this->category = $category; } @@ -307,13 +309,13 @@ class WikiDoc implements \JsonSerializable /** * Add tag * - * @param mixed $tag Tag + * @param Tag $tag Tag * * @return void * * @since 1.0.0 */ - public function addTag($tag) : void + public function addTag(Tag $tag) : void { $this->tags[] = $tag; }