autofixes

This commit is contained in:
Dennis Eichhorn 2020-11-24 18:44:22 +01:00
parent 447b702672
commit c8ee1176fe
14 changed files with 109 additions and 109 deletions

View File

@ -50,7 +50,7 @@ final class Installer extends InstallerAbstract
*/ */
private static function installDefaultUnit() : void private static function installDefaultUnit() : void
{ {
$unit = new Unit(); $unit = new Unit();
$unit->name = 'Orange Management'; $unit->name = 'Orange Management';
UnitMapper::create($unit); UnitMapper::create($unit);

View File

@ -127,12 +127,12 @@ final class ApiController extends Controller
private function updateUnitFromRequest(RequestAbstract $request) : Unit private function updateUnitFromRequest(RequestAbstract $request) : Unit
{ {
/** @var Unit $unit */ /** @var Unit $unit */
$unit = UnitMapper::get((int) $request->getData('id')); $unit = UnitMapper::get((int) $request->getData('id'));
$unit->name = (string) ($request->getData('name') ?? $unit->name); $unit->name = (string) ($request->getData('name') ?? $unit->name);
$unit->descriptionRaw = (string) ($request->getData('description') ?? $unit->descriptionRaw); $unit->descriptionRaw = (string) ($request->getData('description') ?? $unit->descriptionRaw);
$unit->description = Markdown::parse((string) ($request->getData('description') ?? $unit->descriptionRaw)); $unit->description = Markdown::parse((string) ($request->getData('description') ?? $unit->descriptionRaw));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$unit->parent = !empty($parent) ? new NullUnit($parent) : $unit->parent; $unit->parent = !empty($parent) ? new NullUnit($parent) : $unit->parent;
$unit->setStatus((int) ($request->getData('status') ?? $unit->getStatus())); $unit->setStatus((int) ($request->getData('status') ?? $unit->getStatus()));
@ -206,12 +206,12 @@ final class ApiController extends Controller
*/ */
private function createUnitFromRequest(RequestAbstract $request) : Unit private function createUnitFromRequest(RequestAbstract $request) : Unit
{ {
$unit = new Unit(); $unit = new Unit();
$unit->name = (string) $request->getData('name'); $unit->name = (string) $request->getData('name');
$unit->descriptionRaw = (string) ($request->getData('description') ?? ''); $unit->descriptionRaw = (string) ($request->getData('description') ?? '');
$unit->description = Markdown::parse((string) ($request->getData('description') ?? '')); $unit->description = Markdown::parse((string) ($request->getData('description') ?? ''));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$unit->parent = new NullUnit($parent); $unit->parent = new NullUnit($parent);
$unit->setStatus((int) $request->getData('status')); $unit->setStatus((int) $request->getData('status'));
@ -362,15 +362,15 @@ final class ApiController extends Controller
private function updatePositionFromRequest(RequestAbstract $request) : Position private function updatePositionFromRequest(RequestAbstract $request) : Position
{ {
/** @var Position $position */ /** @var Position $position */
$position = PositionMapper::get((int) $request->getData('id')); $position = PositionMapper::get((int) $request->getData('id'));
$position->name = (string) ($request->getData('name') ?? $position->name); $position->name = (string) ($request->getData('name') ?? $position->name);
$position->descriptionRaw = (string) ($request->getData('description') ?? $position->descriptionRaw); $position->descriptionRaw = (string) ($request->getData('description') ?? $position->descriptionRaw);
$position->description = Markdown::parse((string) ($request->getData('description') ?? $position->descriptionRaw)); $position->description = Markdown::parse((string) ($request->getData('description') ?? $position->descriptionRaw));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$position->parent = !empty($parent) ? new NullPosition($parent) : $position->parent; $position->parent = !empty($parent) ? new NullPosition($parent) : $position->parent;
$department = (int) $request->getData('department'); $department = (int) $request->getData('department');
$position->department = !empty($department) ? new NullDepartment($department) : $position->department; $position->department = !empty($department) ? new NullDepartment($department) : $position->department;
$position->setStatus((int) ($request->getData('status') ?? $position->getStatus())); $position->setStatus((int) ($request->getData('status') ?? $position->getStatus()));
@ -423,16 +423,16 @@ final class ApiController extends Controller
*/ */
private function createPositionFromRequest(RequestAbstract $request) : Position private function createPositionFromRequest(RequestAbstract $request) : Position
{ {
$position = new Position(); $position = new Position();
$position->name = (string) ($request->getData('name')); $position->name = (string) ($request->getData('name'));
$position->setStatus((int) $request->getData('status')); $position->setStatus((int) $request->getData('status'));
$position->descriptionRaw = (string) ($request->getData('description') ?? ''); $position->descriptionRaw = (string) ($request->getData('description') ?? '');
$position->description = Markdown::parse((string) ($request->getData('description') ?? '')); $position->description = Markdown::parse((string) ($request->getData('description') ?? ''));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$position->parent = new NullPosition($parent); $position->parent = new NullPosition($parent);
$department = (int) $request->getData('department'); $department = (int) $request->getData('department');
$position->department = new NullDepartment($department); $position->department = new NullDepartment($department);
return $position; return $position;
@ -519,16 +519,16 @@ final class ApiController extends Controller
private function updateDepartmentFromRequest(RequestAbstract $request) : Department private function updateDepartmentFromRequest(RequestAbstract $request) : Department
{ {
/** @var Department $department */ /** @var Department $department */
$department = DepartmentMapper::get((int) $request->getData('id')); $department = DepartmentMapper::get((int) $request->getData('id'));
$department->name = (string) ($request->getData('name') ?? $department->name); $department->name = (string) ($request->getData('name') ?? $department->name);
$department->descriptionRaw = (string) ($request->getData('description') ?? $department->descriptionRaw); $department->descriptionRaw = (string) ($request->getData('description') ?? $department->descriptionRaw);
$department->description = Markdown::parse((string) ($request->getData('description') ?? $department->descriptionRaw)); $department->description = Markdown::parse((string) ($request->getData('description') ?? $department->descriptionRaw));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$department->parent = !empty($parent) ? new NullDepartment($parent) : $department->parent; $department->parent = !empty($parent) ? new NullDepartment($parent) : $department->parent;
$department->setStatus((int) ($request->getData('status') ?? $department->getStatus())); $department->setStatus((int) ($request->getData('status') ?? $department->getStatus()));
$unit = (int) $request->getData('unit'); $unit = (int) $request->getData('unit');
$department->unit = !empty($unit) ? new NullUnit($unit) : $department->unit; $department->unit = !empty($unit) ? new NullUnit($unit) : $department->unit;
return $department; return $department;
@ -601,15 +601,15 @@ final class ApiController extends Controller
*/ */
private function createDepartmentFromRequest(RequestAbstract $request) : Department private function createDepartmentFromRequest(RequestAbstract $request) : Department
{ {
$department = new Department(); $department = new Department();
$department->name = (string) $request->getData('name'); $department->name = (string) $request->getData('name');
$department->setStatus((int) $request->getData('status')); $department->setStatus((int) $request->getData('status'));
$parent = (int) $request->getData('parent'); $parent = (int) $request->getData('parent');
$department->parent = new NullDepartment($parent); $department->parent = new NullDepartment($parent);
$department->unit = new NullUnit((int) ($request->getData('unit') ?? 1)); $department->unit = new NullUnit((int) ($request->getData('unit') ?? 1));
$department->descriptionRaw = (string) ($request->getData('description') ?? ''); $department->descriptionRaw = (string) ($request->getData('description') ?? '');
$department->description = Markdown::parse((string) ($request->getData('description') ?? '')); $department->description = Markdown::parse((string) ($request->getData('description') ?? ''));
return $department; return $department;
} }

View File

@ -91,9 +91,9 @@ class Department implements \JsonSerializable, ArrayableInterface
*/ */
public function __construct(string $name = '') public function __construct(string $name = '')
{ {
$this->name = $name; $this->name = $name;
$this->parent = new NullDepartment(); $this->parent = new NullDepartment();
$this->unit = new NullUnit(); $this->unit = new NullUnit();
} }
/** /**

View File

@ -33,7 +33,7 @@ final class NullDepartment extends Department
*/ */
public function __construct(int $id = 0) public function __construct(int $id = 0)
{ {
$this->id = $id; $this->id = $id;
$this->unit = new NullUnit(); $this->unit = new NullUnit();
} }
} }

View File

@ -35,7 +35,7 @@ final class NullUnit extends Unit
*/ */
public function __construct(int $id = 0) public function __construct(int $id = 0)
{ {
$this->id = $id; $this->id = $id;
$this->image = new NullMedia(); $this->image = new NullMedia();
} }
} }

View File

@ -89,7 +89,7 @@ class Position implements \JsonSerializable, ArrayableInterface
*/ */
public function __construct() public function __construct()
{ {
$this->parent = new NullPosition(); $this->parent = new NullPosition();
$this->department = new NullDepartment(); $this->department = new NullDepartment();
} }

View File

@ -91,7 +91,7 @@ class Unit implements \JsonSerializable, ArrayableInterface
*/ */
public function __construct() public function __construct()
{ {
$this->image = new NullMedia(); $this->image = new NullMedia();
$this->parent = new NullUnit(); $this->parent = new NullUnit();
} }

View File

@ -13,8 +13,8 @@
declare(strict_types=1); declare(strict_types=1);
use Modules\Media\Models\NullMedia; use Modules\Media\Models\NullMedia;
use phpOMS\Uri\UriFactory;
use Modules\Organization\Models\Status; use Modules\Organization\Models\Status;
use phpOMS\Uri\UriFactory;
/** /**
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this

View File

@ -30,10 +30,10 @@ class DepartmentMapperTest extends \PHPUnit\Framework\TestCase
*/ */
public function testCRUD() : void public function testCRUD() : void
{ {
$department = new Department(); $department = new Department();
$department->name = 'Management'; $department->name = 'Management';
$department->description = 'Description'; $department->description = 'Description';
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
$id = DepartmentMapper::create($department); $id = DepartmentMapper::create($department);
@ -56,67 +56,67 @@ class DepartmentMapperTest extends \PHPUnit\Framework\TestCase
$first = 2; $first = 2;
/* 2 */ /* 2 */
$department = new Department(); $department = new Department();
$department->name = 'HR'; $department->name = 'HR';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 3 */ /* 3 */
$department = new Department(); $department = new Department();
$department->name = 'QM'; $department->name = 'QM';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 4 */ /* 4 */
$department = new Department(); $department = new Department();
$department->name = 'Sales'; $department->name = 'Sales';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 5 */ /* 5 */
$department = new Department(); $department = new Department();
$department->name = 'Shipping'; $department->name = 'Shipping';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first + 3); $department->parent = new NullDepartment($first + 3);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 6 */ /* 6 */
$department = new Department(); $department = new Department();
$department->name = 'Purchase'; $department->name = 'Purchase';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 7 */ /* 7 */
$department = new Department(); $department = new Department();
$department->name = 'Arrival'; $department->name = 'Arrival';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first + 5); $department->parent = new NullDepartment($first + 5);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 8 */ /* 8 */
$department = new Department(); $department = new Department();
$department->name = 'Accounting'; $department->name = 'Accounting';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
/* 9 */ /* 9 */
$department = new Department(); $department = new Department();
$department->name = 'Production'; $department->name = 'Production';
$department->description = 'Description'; $department->description = 'Description';
$department->parent = new NullDepartment($first); $department->parent = new NullDepartment($first);
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create($department);
} }
} }

View File

@ -112,12 +112,12 @@ class DepartmentTest extends \PHPUnit\Framework\TestCase
*/ */
public function testSerialize() : void public function testSerialize() : void
{ {
$this->department->name = 'Name'; $this->department->name = 'Name';
$this->department->description = 'Description'; $this->department->description = 'Description';
$this->department->descriptionRaw = 'DescriptionRaw'; $this->department->descriptionRaw = 'DescriptionRaw';
$this->department->setStatus(Status::ACTIVE); $this->department->setStatus(Status::ACTIVE);
$this->department->parent = ($p = new NullDepartment(1)); $this->department->parent = ($p = new NullDepartment(1));
$this->department->unit = ($u = new NullUnit(1)); $this->department->unit = ($u = new NullUnit(1));
self::assertEquals($this->department->toArray(), $this->department->jsonSerialize()); self::assertEquals($this->department->toArray(), $this->department->jsonSerialize());
self::assertEquals( self::assertEquals(

View File

@ -29,8 +29,8 @@ class PositionMapperTest extends \PHPUnit\Framework\TestCase
*/ */
public function testCRUD() : void public function testCRUD() : void
{ {
$position = new Position(); $position = new Position();
$position->name = 'CEO'; $position->name = 'CEO';
$position->description = 'Description'; $position->description = 'Description';
$id = PositionMapper::create($position); $id = PositionMapper::create($position);
@ -53,59 +53,59 @@ class PositionMapperTest extends \PHPUnit\Framework\TestCase
$first = 2; $first = 2;
/* 4 */ /* 4 */
$position = new Position(); $position = new Position();
$position->name = 'CFO'; $position->name = 'CFO';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first); $position->parent = new NullPosition($first);
$id = PositionMapper::create($position); $id = PositionMapper::create($position);
/* 5 */ /* 5 */
$position = new Position(); $position = new Position();
$position->name = 'Accountant'; $position->name = 'Accountant';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($id); $position->parent = new NullPosition($id);
PositionMapper::create($position); PositionMapper::create($position);
/* 6 */ /* 6 */
$position = new Position(); $position = new Position();
$position->name = 'Controller'; $position->name = 'Controller';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($id); $position->parent = new NullPosition($id);
PositionMapper::create($position); PositionMapper::create($position);
/* 7 */ /* 7 */
$position = new Position(); $position = new Position();
$position->name = 'Sales Director'; $position->name = 'Sales Director';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first); $position->parent = new NullPosition($first);
PositionMapper::create($position); PositionMapper::create($position);
/* 8 */ /* 8 */
$position = new Position(); $position = new Position();
$position->name = 'Purchase Director'; $position->name = 'Purchase Director';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first); $position->parent = new NullPosition($first);
PositionMapper::create($position); PositionMapper::create($position);
/* 9 */ /* 9 */
$position = new Position(); $position = new Position();
$position->name = 'Territory Manager'; $position->name = 'Territory Manager';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first + 4); $position->parent = new NullPosition($first + 4);
PositionMapper::create($position); PositionMapper::create($position);
/* 10 */ /* 10 */
$position = new Position(); $position = new Position();
$position->name = 'Territory Sales Assistant'; $position->name = 'Territory Sales Assistant';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first + 6); $position->parent = new NullPosition($first + 6);
PositionMapper::create($position); PositionMapper::create($position);
/* 11 */ /* 11 */
$position = new Position(); $position = new Position();
$position->name = 'Domestic Sales Manager'; $position->name = 'Domestic Sales Manager';
$position->description = 'Description'; $position->description = 'Description';
$position->parent = new NullPosition($first + 4); $position->parent = new NullPosition($first + 4);
PositionMapper::create($position); PositionMapper::create($position);
} }
} }

View File

@ -112,11 +112,11 @@ class PositionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testSerialize() : void public function testSerialize() : void
{ {
$this->position->name = 'Name'; $this->position->name = 'Name';
$this->position->description = 'Description'; $this->position->description = 'Description';
$this->position->descriptionRaw = 'DescriptionRaw'; $this->position->descriptionRaw = 'DescriptionRaw';
$this->position->setStatus(Status::ACTIVE); $this->position->setStatus(Status::ACTIVE);
$this->position->parent = ($p = new NullPosition(1)); $this->position->parent = ($p = new NullPosition(1));
$this->position->department = ($d = new NullDepartment(1)); $this->position->department = ($d = new NullDepartment(1));
self::assertEquals($this->position->toArray(), $this->position->jsonSerialize()); self::assertEquals($this->position->toArray(), $this->position->jsonSerialize());

View File

@ -29,10 +29,10 @@ class UnitMapperTest extends \PHPUnit\Framework\TestCase
*/ */
public function testCRUD() : void public function testCRUD() : void
{ {
$unit = new Unit(); $unit = new Unit();
$unit->name = 'Scrooge Inc.'; $unit->name = 'Scrooge Inc.';
$unit->description = 'Description'; $unit->description = 'Description';
$unit->parent = new NullUnit(1); $unit->parent = new NullUnit(1);
$id = UnitMapper::create($unit); $id = UnitMapper::create($unit);

View File

@ -112,12 +112,12 @@ class UnitTest extends \PHPUnit\Framework\TestCase
*/ */
public function testSerialize() : void public function testSerialize() : void
{ {
$this->unit->name = 'Name'; $this->unit->name = 'Name';
$this->unit->description = 'Description'; $this->unit->description = 'Description';
$this->unit->descriptionRaw = 'DescriptionRaw'; $this->unit->descriptionRaw = 'DescriptionRaw';
$this->unit->setStatus(Status::ACTIVE); $this->unit->setStatus(Status::ACTIVE);
$this->unit->parent = ($p = new NullUnit(1)); $this->unit->parent = ($p = new NullUnit(1));
$this->unit->image = ($i = new NullMedia(1)); $this->unit->image = ($i = new NullMedia(1));
self::assertEquals($this->unit->toArray(), $this->unit->jsonSerialize()); self::assertEquals($this->unit->toArray(), $this->unit->jsonSerialize());
self::assertEquals( self::assertEquals(