diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 716fef3..3e35103 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -137,8 +137,8 @@ final class ApiController extends Controller $unit->descriptionRaw = $request->getDataString('description') ?? $unit->descriptionRaw; $unit->description = Markdown::parse($request->getDataString('description') ?? $unit->descriptionRaw); - $parent = (int) $request->getData('parent'); - $unit->parent = empty($parent) ? $unit->parent : new NullUnit($parent); + $parent = $request->getDataInt('parent') ?? 0; + $unit->parent = $parent === 0 ? $unit->parent : new NullUnit($parent); $unit->setStatus($request->getDataInt('status') ?? $unit->getStatus()); return $unit; diff --git a/Models/Department.php b/Models/Department.php index 73b14e8..e5c6eac 100755 --- a/Models/Department.php +++ b/Models/Department.php @@ -43,10 +43,10 @@ class Department implements \JsonSerializable /** * Parent * - * @var self + * @var null|self * @since 1.0.0 */ - public self $parent; + public ?self $parent = null; /** * Status @@ -90,7 +90,6 @@ class Department implements \JsonSerializable public function __construct(string $name = '') { $this->name = $name; - $this->parent = new NullDepartment(); $this->unit = new NullUnit(); } diff --git a/Models/Position.php b/Models/Position.php index bc3e2ad..cee22c5 100755 --- a/Models/Position.php +++ b/Models/Position.php @@ -43,10 +43,10 @@ class Position implements \JsonSerializable /** * Parent * - * @var Position + * @var null|Position * @since 1.0.0 */ - public self $parent; + public ?self $parent = null; /** * Department @@ -87,7 +87,6 @@ class Position implements \JsonSerializable */ public function __construct() { - $this->parent = new NullPosition(); $this->department = new NullDepartment(); } @@ -129,7 +128,7 @@ class Position implements \JsonSerializable 'description' => $this->description, 'descriptionRaw' => $this->descriptionRaw, 'department' => $this->department ?? new NullDepartment(), - 'parent' => $this->parent ?? null, + 'parent' => $this->parent, ]; } diff --git a/Models/Unit.php b/Models/Unit.php index b08b3a7..96171f8 100755 --- a/Models/Unit.php +++ b/Models/Unit.php @@ -56,10 +56,10 @@ class Unit implements \JsonSerializable /** * Parent * - * @var Unit + * @var null|Unit * @since 1.0.0 */ - public self $parent; + public ?self $parent; /** * Description. @@ -97,7 +97,6 @@ class Unit implements \JsonSerializable public function __construct() { $this->image = new NullMedia(); - $this->parent = new NullUnit(); $this->mainAddress = new NullAddress(); } @@ -150,7 +149,7 @@ class Unit implements \JsonSerializable 'status' => $this->status, 'description' => $this->description, 'descriptionRaw' => $this->descriptionRaw, - 'parent' => $this->parent ?? null, + 'parent' => $this->parent, 'image' => $this->image, ]; } diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 5843b67..3b921bc 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -82,7 +82,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $this->app->accountManager->add($account); $this->app->router = new WebRouter(); - $this->module = $this->app->moduleManager->get('Organization'); + $this->module = $this->app->moduleManager->get('Organization', 'Api'); TestUtils::setMember($this->module, 'app', $this->app); }