From 01e44c0e98c90d48ed207735da33c85c4b53fa80 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 --- Controller/ApiController.php | 15 +++++++++------ Models/Department.php | 24 ++++++++++++------------ Models/NullDepartment.php | 11 +++++++++++ Models/NullPosition.php | 11 +++++++++++ Models/NullUnit.php | 11 +++++++++++ Models/Position.php | 26 +++++++++++++------------- Models/Unit.php | 14 +++++++------- 7 files changed, 74 insertions(+), 38 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 166e4c7..c6369c2 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -16,13 +16,16 @@ namespace Modules\Organization\Controller; use Modules\Organization\Models\Department; use Modules\Organization\Models\DepartmentMapper; +use Modules\Organization\Models\NullDepartment; +use Modules\Organization\Models\NullPosition; +use Modules\Organization\Models\NullUnit; use Modules\Organization\Models\Position; use Modules\Organization\Models\PositionMapper; use Modules\Organization\Models\SettingsEnum; use Modules\Organization\Models\Status; + use Modules\Organization\Models\Unit; use Modules\Organization\Models\UnitMapper; - use phpOMS\Account\GroupStatus; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\NotificationLevel; @@ -204,7 +207,7 @@ final class ApiController extends Controller $unit->setDescription(Markdown::parse((string) ($request->getData('description') ?? ''))); $parent = (int) $request->getData('parent'); - $unit->setParent(!empty($parent) ? $parent : null); + $unit->setParent(!empty($parent) ? new NullUnit($parent) : null); $unit->setStatus((int) $request->getData('status')); return $unit; @@ -376,10 +379,10 @@ final class ApiController extends Controller $position->setDescription(Markdown::parse((string) ($request->getData('description') ?? ''))); $parent = (int) $request->getData('parent'); - $position->setParent(!empty($parent) ? $parent : null); + $position->setParent(!empty($parent) ? new NullPosition($parent) : null); $department = (int) $request->getData('department'); - $position->setDepartment(!empty($department) ? $department : null); + $position->setDepartment(!empty($department) ? new NullDepartment($department) : null); return $position; } @@ -547,8 +550,8 @@ final class ApiController extends Controller $department->setStatus((int) $request->getData('status')); $parent = (int) $request->getData('parent'); - $department->setParent(!empty($parent) ? $parent : null); - $department->setUnit((int) ($request->getData('unit') ?? 1)); + $department->setParent(!empty($parent) ? new NullDepartment($parent) : null); + $department->setUnit(new NullUnit((int) ($request->getData('unit') ?? 1))); $department->setDescriptionRaw((string) ($request->getData('description') ?? '')); $department->setDescription(Markdown::parse((string) ($request->getData('description') ?? ''))); diff --git a/Models/Department.php b/Models/Department.php index be9b50e..41e74ef 100644 --- a/Models/Department.php +++ b/Models/Department.php @@ -48,7 +48,7 @@ class Department implements ArrayableInterface, \JsonSerializable * @var mixed * @since 1.0.0 */ - protected $parent = null; + protected ?self $parent = null; /** * Status @@ -61,10 +61,10 @@ class Department implements ArrayableInterface, \JsonSerializable /** * Unit this department belongs to * - * @var mixed + * @var Unit * @since 1.0.0 */ - protected $unit = 1; + protected Unit $unit; /** * Description. @@ -135,11 +135,11 @@ class Department implements ArrayableInterface, \JsonSerializable /** * Get parent * - * @return mixed + * @return Department * * @since 1.0.0 */ - public function getParent() + public function getParent() : self { return $this->parent ?? new NullDepartment(); } @@ -147,13 +147,13 @@ class Department implements ArrayableInterface, \JsonSerializable /** * Set parent * - * @param mixed $parent Parent + * @param null|self $parent Parent * * @return void * * @since 1.0.0 */ - public function setParent($parent) : void + public function setParent(?self $parent) : void { $this->parent = $parent; } @@ -187,11 +187,11 @@ class Department implements ArrayableInterface, \JsonSerializable /** * Get unit * - * @return mixed + * @return Unit * * @since 1.0.0 */ - public function getUnit() + public function getUnit() : Unit { return $this->unit ?? new NullUnit(); } @@ -199,13 +199,13 @@ class Department implements ArrayableInterface, \JsonSerializable /** * Set unit * - * @param mixed $unit Unit + * @param Unit $unit Unit * * @return void * * @since 1.0.0 */ - public function setUnit($unit) : void + public function setUnit(Unit $unit) : void { $this->unit = $unit; } @@ -271,7 +271,7 @@ class Department implements ArrayableInterface, \JsonSerializable 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, - 'unit' => $this->unit, + 'unit' => $this->unit ?? new NullUnit(), ]; } diff --git a/Models/NullDepartment.php b/Models/NullDepartment.php index d0b7c12..d1f6907 100644 --- a/Models/NullDepartment.php +++ b/Models/NullDepartment.php @@ -24,4 +24,15 @@ namespace Modules\Organization\Models; */ final class NullDepartment extends Department { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/NullPosition.php b/Models/NullPosition.php index 09f58f3..2ae48d7 100644 --- a/Models/NullPosition.php +++ b/Models/NullPosition.php @@ -24,4 +24,15 @@ namespace Modules\Organization\Models; */ final class NullPosition extends Position { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/NullUnit.php b/Models/NullUnit.php index 30ee574..cc09f5f 100644 --- a/Models/NullUnit.php +++ b/Models/NullUnit.php @@ -24,4 +24,15 @@ namespace Modules\Organization\Models; */ final class NullUnit extends Unit { + /** + * Constructor + * + * @param int $id Model id + * + * @since 1.0.0 + */ + public function __construct(int $id = 0) + { + $this->id = $id; + } } diff --git a/Models/Position.php b/Models/Position.php index 9565905..e04c71c 100644 --- a/Models/Position.php +++ b/Models/Position.php @@ -45,18 +45,18 @@ class Position implements ArrayableInterface, \JsonSerializable /** * Parent * - * @var mixed + * @var null|Position * @since 1.0.0 */ - private $parent = null; + private ?self $parent = null; /** * Department * - * @var mixed + * @var null|Department * @since 1.0.0 */ - private $department = null; + private ?Department $department = null; /** * Description. @@ -123,11 +123,11 @@ class Position implements ArrayableInterface, \JsonSerializable /** * Get parent * - * @return mixed + * @return Position * * @since 1.0.0 */ - public function getParent() + public function getParent() : self { return $this->parent ?? new NullPosition(); } @@ -135,13 +135,13 @@ class Position implements ArrayableInterface, \JsonSerializable /** * Set parent * - * @param mixed $parent Parent + * @param null|Position $parent Parent * * @return void * * @since 1.0.0 */ - public function setParent($parent) : void + public function setParent(?self $parent) : void { $this->parent = $parent; } @@ -149,11 +149,11 @@ class Position implements ArrayableInterface, \JsonSerializable /** * Get parent * - * @return mixed + * @return Department * * @since 1.0.0 */ - public function getDepartment() + public function getDepartment() : Department { return $this->department ?? new NullDepartment(); } @@ -161,13 +161,13 @@ class Position implements ArrayableInterface, \JsonSerializable /** * Set department * - * @param mixed $department Department + * @param null|Department $department Department * * @return void * * @since 1.0.0 */ - public function setDepartment($department) : void + public function setDepartment(?Department $department) : void { $this->department = $department; } @@ -259,7 +259,7 @@ class Position implements ArrayableInterface, \JsonSerializable 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, - 'department' => $this->department, + 'department' => $this->department ?? new NullDepartment(), 'parent' => $this->parent, ]; } diff --git a/Models/Unit.php b/Models/Unit.php index a5591d9..f5c6697 100644 --- a/Models/Unit.php +++ b/Models/Unit.php @@ -32,7 +32,7 @@ class Unit implements ArrayableInterface, \JsonSerializable * @var int * @since 1.0.0 */ - private int $id = 0; + protected int $id = 0; /** * Name. @@ -45,10 +45,10 @@ class Unit implements ArrayableInterface, \JsonSerializable /** * Parent * - * @var mixed + * @var null|Unit * @since 1.0.0 */ - private $parent = null; + private ?self $parent = null; /** * Description. @@ -115,11 +115,11 @@ class Unit implements ArrayableInterface, \JsonSerializable /** * Get parent * - * @return mixed + * @return Unit * * @since 1.0.0 */ - public function getParent() + public function getParent() : self { return $this->parent ?? new NullUnit(); } @@ -127,13 +127,13 @@ class Unit implements ArrayableInterface, \JsonSerializable /** * Set parent * - * @param mixed $parent Parent + * @param null|Unit $parent Parent * * @return void * * @since 1.0.0 */ - public function setParent($parent) : void + public function setParent(?self $parent) : void { $this->parent = $parent; }