From c1e0f84592233117987b583ee4c3d093e3556954 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 16 Nov 2021 00:05:43 +0100 Subject: [PATCH] cs fixes, bug fixes, code coverage --- CONTRIBUTING.md | 4 +--- Controller/ApiController.php | 16 ++++++++-------- Models/Employee.php | 8 ++++---- Models/EmployeeEducationHistory.php | 12 ++++++------ Models/EmployeeHistory.php | 3 --- Models/EmployeeWorkHistory.php | 8 ++++---- Models/NullEmployeeEducationHistory.php | 2 +- Models/NullEmployeeHistory.php | 2 +- Models/NullEmployeeWorkHistory.php | 2 +- tests/Controller/ApiControllerTest.php | 16 +++++++--------- tests/Models/EmployeeEducationHistoryTest.php | 17 +++++++++-------- tests/Models/EmployeeTest.php | 10 ++++------ tests/Models/EmployeeWorkHistoryTest.php | 1 + tests/Models/EmplyeeHistoryTest.php | 1 + 14 files changed, 48 insertions(+), 54 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cab9f5e..ad8944e 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,9 +12,7 @@ If you have a good idea for improvement feel free to create a new issue with all ### Issues -Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the `Project.md` file in the `Docs` repository. - -The issue information can be used to provide additional information such as priority, difficulty and type. For your first issue try to find a issue marked `[d:first]` or `[d:beginner]`. +Feel free to grab any open issue implement it and create a new pull request. Most issues can be found in the code marked with `@todo` or in the [PROJECT.md](https://github.com/Orange-Management/Docs/blob/master/Project/PROJECT.md) file. ### Code Style diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 26e2b36..3b1861d 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -268,11 +268,11 @@ final class ApiController extends Controller */ private function createEmployeeHistoryFromRequest(RequestAbstract $request) : EmployeeHistory { - $history = new EmployeeHistory((int) ($request->getData('employee') ?? 0)); - $history->unit = (int) ($request->getData('unit') ?? 0); + $history = new EmployeeHistory((int) ($request->getData('employee') ?? 0)); + $history->unit = (int) ($request->getData('unit') ?? 0); $history->department = (int) ($request->getData('department') ?? 0); - $history->position = (int) ($request->getData('position') ?? 0); - $history->start = new \DateTime($request->getData('start') ?? 'now'); + $history->position = (int) ($request->getData('position') ?? 0); + $history->start = new \DateTime($request->getData('start') ?? 'now'); if (!empty($request->getData('end'))) { $history->end = new \DateTime($request->getData('end')); @@ -342,8 +342,8 @@ final class ApiController extends Controller */ private function createEmployeeWorkHistoryFromRequest(RequestAbstract $request) : EmployeeWorkHistory { - $history = new EmployeeWorkHistory((int) ($request->getData('employee') ?? 0)); - $history->start = new \DateTime($request->getData('start') ?? 'now'); + $history = new EmployeeWorkHistory((int) ($request->getData('employee') ?? 0)); + $history->start = new \DateTime($request->getData('start') ?? 'now'); $history->jobTitle = $request->getData('title'); $history->address->name = $request->getData('name'); $history->address->address = $request->getData('address') ?? ''; @@ -421,8 +421,8 @@ final class ApiController extends Controller */ private function createEmployeeEducationHistoryFromRequest(RequestAbstract $request) : EmployeeEducationHistory { - $history = new EmployeeEducationHistory((int) ($request->getData('employee') ?? 0)); - $history->start = new \DateTime($request->getData('start') ?? 'now'); + $history = new EmployeeEducationHistory((int) ($request->getData('employee') ?? 0)); + $history->start = new \DateTime($request->getData('start') ?? 'now'); $history->educationTitle = $request->getData('title'); $history->score = $request->getData('score') ?? ''; $history->passed = (bool) ($request->getData('passed') ?? true); diff --git a/Models/Employee.php b/Models/Employee.php index 5caa6cf..b2654e6 100755 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -284,10 +284,10 @@ class Employee implements \JsonSerializable, ArrayableInterface public function toArray() : array { return [ - 'id' => $this->id, - 'profile' => $this->profile, - 'history' => $this->companyHistory, - 'workHistory' => $this->workHistory, + 'id' => $this->id, + 'profile' => $this->profile, + 'history' => $this->companyHistory, + 'workHistory' => $this->workHistory, 'educationHistory' => $this->educationHistory, ]; } diff --git a/Models/EmployeeEducationHistory.php b/Models/EmployeeEducationHistory.php index dfe5c9c..d83e2df 100755 --- a/Models/EmployeeEducationHistory.php +++ b/Models/EmployeeEducationHistory.php @@ -108,13 +108,13 @@ class EmployeeEducationHistory implements \JsonSerializable, ArrayableInterface public function toArray() : array { return [ - 'id' => $this->id, - 'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee, + 'id' => $this->id, + 'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee, 'educationTitle' => $this->educationTitle, - 'passed' => $this->passed, - 'score' => $this->score, - 'start' => $this->start, - 'end' => $this->end, + 'passed' => $this->passed, + 'score' => $this->score, + 'start' => $this->start, + 'end' => $this->end, ]; } diff --git a/Models/EmployeeHistory.php b/Models/EmployeeHistory.php index 13d594c..347b59b 100755 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -16,9 +16,6 @@ namespace Modules\HumanResourceManagement\Models; use Modules\Media\Models\Media; use Modules\Organization\Models\Department; -use Modules\Organization\Models\NullDepartment; -use Modules\Organization\Models\NullPosition; -use Modules\Organization\Models\NullUnit; use Modules\Organization\Models\Position; use Modules\Organization\Models\Unit; use phpOMS\Contract\ArrayableInterface; diff --git a/Models/EmployeeWorkHistory.php b/Models/EmployeeWorkHistory.php index e8456ea..18c29ab 100755 --- a/Models/EmployeeWorkHistory.php +++ b/Models/EmployeeWorkHistory.php @@ -104,11 +104,11 @@ class EmployeeWorkHistory implements \JsonSerializable, ArrayableInterface public function toArray() : array { return [ - 'id' => $this->id, - 'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee, + 'id' => $this->id, + 'employee' => !\is_int($this->employee) ? $this->employee->getId() : $this->employee, 'jobTitle' => $this->jobTitle, - 'start' => $this->start, - 'end' => $this->end, + 'start' => $this->start, + 'end' => $this->end, ]; } diff --git a/Models/NullEmployeeEducationHistory.php b/Models/NullEmployeeEducationHistory.php index 5664afa..46b1daa 100755 --- a/Models/NullEmployeeEducationHistory.php +++ b/Models/NullEmployeeEducationHistory.php @@ -24,7 +24,7 @@ namespace Modules\HumanResourceManagement\Models; */ final class NullEmployeeEducationHistory extends EmployeeEducationHistory { - /** + /** * Constructor * * @param int $id Model id diff --git a/Models/NullEmployeeHistory.php b/Models/NullEmployeeHistory.php index 6dcd324..e792aa0 100755 --- a/Models/NullEmployeeHistory.php +++ b/Models/NullEmployeeHistory.php @@ -24,7 +24,7 @@ namespace Modules\HumanResourceManagement\Models; */ final class NullEmployeeHistory extends EmployeeHistory { - /** + /** * Constructor * * @param int $id Model id diff --git a/Models/NullEmployeeWorkHistory.php b/Models/NullEmployeeWorkHistory.php index ab32a11..c877b00 100755 --- a/Models/NullEmployeeWorkHistory.php +++ b/Models/NullEmployeeWorkHistory.php @@ -24,7 +24,7 @@ namespace Modules\HumanResourceManagement\Models; */ final class NullEmployeeWorkHistory extends EmployeeWorkHistory { - /** + /** * Constructor * * @param int $id Model id diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index a2900fe..1a6b12f 100644 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -16,6 +16,11 @@ namespace Modules\HumanResourceManagement\tests\Controller; use Model\CoreSettings; use Modules\Admin\Models\AccountPermission; +use Modules\Organization\Models\Department; +use Modules\Organization\Models\DepartmentMapper; +use Modules\Organization\Models\NullUnit; +use Modules\Organization\Models\Position; +use Modules\Organization\Models\PositionMapper; use phpOMS\Account\Account; use phpOMS\Account\AccountManager; use phpOMS\Account\PermissionType; @@ -23,6 +28,7 @@ use phpOMS\Application\ApplicationAbstract; use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Dispatcher\Dispatcher; use phpOMS\Event\EventManager; +use phpOMS\Localization\ISO3166TwoEnum; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; @@ -30,16 +36,8 @@ use phpOMS\Module\ModuleAbstract; use phpOMS\Module\ModuleManager; use phpOMS\Router\WebRouter; use phpOMS\Uri\HttpUri; -use phpOMS\Utils\TestUtils; use phpOMS\Utils\RnG\DateTime; -use phpOMS\Localization\ISO3166TwoEnum; -use Modules\Organization\Models\Department; -use Modules\Organization\Models\DepartmentMapper; -use Modules\Organization\Models\NullDepartment; -use Modules\Organization\Models\NullUnit; -use Modules\Organization\Models\NullPosition; -use Modules\Organization\Models\Position; -use Modules\Organization\Models\PositionMapper; +use phpOMS\Utils\TestUtils; /** * @testdox Modules\HumanResourceManagement\tests\Controller\ApiControllerTest: HumanResourceManagement api controller diff --git a/tests/Models/EmployeeEducationHistoryTest.php b/tests/Models/EmployeeEducationHistoryTest.php index 07a6b6e..b03ecad 100644 --- a/tests/Models/EmployeeEducationHistoryTest.php +++ b/tests/Models/EmployeeEducationHistoryTest.php @@ -30,6 +30,7 @@ final class EmployeeEducationHistoryTest extends \PHPUnit\Framework\TestCase { $this->history = new EmployeeEducationHistory(); } + /** * @covers Modules\HumanResourceManagement\Models\EmployeeEducationHistory * @group module @@ -52,22 +53,22 @@ final class EmployeeEducationHistoryTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->history->employee = 2; + $this->history->employee = 2; $this->history->educationTitle = 'title'; - $this->history->score = '69'; - $this->history->passed = false; + $this->history->score = '69'; + $this->history->passed = false; $serialized = $this->history->jsonSerialize(); unset($serialized['start']); self::assertEquals( [ - 'id' => 0, - 'employee' => 2, + 'id' => 0, + 'employee' => 2, 'educationTitle' => 'title', - 'passed' => false, - 'score' => '69', - 'end' => null, + 'passed' => false, + 'score' => '69', + 'end' => null, ], $serialized ); diff --git a/tests/Models/EmployeeTest.php b/tests/Models/EmployeeTest.php index 2f1514a..6dd4c13 100755 --- a/tests/Models/EmployeeTest.php +++ b/tests/Models/EmployeeTest.php @@ -14,12 +14,10 @@ declare(strict_types=1); namespace Modules\HumanResourceManagement\tests\Models; -use Modules\Profile\Models\Profile; -use Modules\Profile\Models\NullProfile; use Modules\HumanResourceManagement\Models\Employee; +use Modules\HumanResourceManagement\Models\EmployeeEducationHistory; use Modules\HumanResourceManagement\Models\EmployeeHistory; use Modules\HumanResourceManagement\Models\EmployeeWorkHistory; -use Modules\HumanResourceManagement\Models\EmployeeEducationHistory; /** * @internal @@ -111,9 +109,9 @@ final class EmployeeTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ - 'id' => 0, - 'history' => [], - 'workHistory' => [], + 'id' => 0, + 'history' => [], + 'workHistory' => [], 'educationHistory' => [], ], $serialized diff --git a/tests/Models/EmployeeWorkHistoryTest.php b/tests/Models/EmployeeWorkHistoryTest.php index 6aa73c9..13620f1 100644 --- a/tests/Models/EmployeeWorkHistoryTest.php +++ b/tests/Models/EmployeeWorkHistoryTest.php @@ -30,6 +30,7 @@ final class EmployeeWorkHistoryTest extends \PHPUnit\Framework\TestCase { $this->history = new EmployeeWorkHistory(); } + /** * @covers Modules\HumanResourceManagement\Models\EmployeeWorkHistory * @group module diff --git a/tests/Models/EmplyeeHistoryTest.php b/tests/Models/EmplyeeHistoryTest.php index c27e3a7..4f651cc 100755 --- a/tests/Models/EmplyeeHistoryTest.php +++ b/tests/Models/EmplyeeHistoryTest.php @@ -30,6 +30,7 @@ final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase { $this->history = new EmployeeHistory(); } + /** * @covers Modules\HumanResourceManagement\Models\EmployeeHistory * @group module