From 064fef7d82745fad46c763aae115482291415ab9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 27 Jan 2023 22:12:09 +0100 Subject: [PATCH] phpstan, phpcs, phpunit fixes --- Models/Employee.php | 22 ++++++++++------------ Models/EmployeeEducationHistory.php | 21 ++++++++++----------- Models/EmployeeEducationHistoryMapper.php | 4 ++-- Models/EmployeeHistory.php | 21 ++++++++++----------- Models/EmployeeHistoryMapper.php | 4 ++-- Models/EmployeeMapper.php | 6 +++--- Models/EmployeeWorkHistory.php | 21 ++++++++++----------- Models/EmployeeWorkHistoryMapper.php | 4 ++-- 8 files changed, 49 insertions(+), 54 deletions(-) diff --git a/Models/Employee.php b/Models/Employee.php index 90d3750..9eca093 100755 --- a/Models/Employee.php +++ b/Models/Employee.php @@ -178,16 +178,16 @@ class Employee implements \JsonSerializable /** * Get media file by type * - * @param null|int $type Media type + * @param int $type Media type * * @return Media * * @since 1.0.0 */ - public function getFileByType(int $type = null) : Media + public function getFileByType(int $type) : Media { foreach ($this->files as $file) { - if ($file->type === $type) { + if ($file->hasMediaTypeId($type)) { return $file; } } @@ -196,26 +196,24 @@ class Employee implements \JsonSerializable } /** - * Get all media files by type + * Get all media files by type name * - * @param null|int $type Media type + * @param string $type Media type * - * @return Media[] + * @return Media * * @since 1.0.0 */ - public function getFilesByType(int $type = null) : array + public function getFileByTypeName(string $type) : Media { - $files = []; foreach ($this->files as $file) { - if ($file->type === $type) { - $files[] = $file; + if ($file->hasMediaTypeName($type)) { + return $file; } } - return $files; + return new NullMedia(); } - /** * Get employee company history. * diff --git a/Models/EmployeeEducationHistory.php b/Models/EmployeeEducationHistory.php index a069987..9867a6e 100755 --- a/Models/EmployeeEducationHistory.php +++ b/Models/EmployeeEducationHistory.php @@ -117,16 +117,16 @@ class EmployeeEducationHistory implements \JsonSerializable /** * Get media file by type * - * @param null|int $type Media type + * @param int $type Media type * * @return Media * * @since 1.0.0 */ - public function getFileByType(int $type = null) : Media + public function getFileByType(int $type) : Media { foreach ($this->files as $file) { - if ($file->type === $type) { + if ($file->hasMediaTypeId($type)) { return $file; } } @@ -135,24 +135,23 @@ class EmployeeEducationHistory implements \JsonSerializable } /** - * Get all media files by type + * Get all media files by type name * - * @param null|int $type Media type + * @param string $type Media type * - * @return Media[] + * @return Media * * @since 1.0.0 */ - public function getFilesByType(int $type = null) : array + public function getFileByTypeName(string $type) : Media { - $files = []; foreach ($this->files as $file) { - if ($file->type === $type) { - $files[] = $file; + if ($file->hasMediaTypeName($type)) { + return $file; } } - return $files; + return new NullMedia(); } /** diff --git a/Models/EmployeeEducationHistoryMapper.php b/Models/EmployeeEducationHistoryMapper.php index 3384ba4..c78faf6 100755 --- a/Models/EmployeeEducationHistoryMapper.php +++ b/Models/EmployeeEducationHistoryMapper.php @@ -47,7 +47,7 @@ final class EmployeeEducationHistoryMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -60,7 +60,7 @@ final class EmployeeEducationHistoryMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/Models/EmployeeHistory.php b/Models/EmployeeHistory.php index 85a73a6..0bcbd6b 100755 --- a/Models/EmployeeHistory.php +++ b/Models/EmployeeHistory.php @@ -140,16 +140,16 @@ class EmployeeHistory implements \JsonSerializable /** * Get media file by type * - * @param null|int $type Media type + * @param int $type Media type * * @return Media * * @since 1.0.0 */ - public function getFileByType(int $type = null) : Media + public function getFileByType(int $type) : Media { foreach ($this->files as $file) { - if ($file->type === $type) { + if ($file->hasMediaTypeId($type)) { return $file; } } @@ -158,24 +158,23 @@ class EmployeeHistory implements \JsonSerializable } /** - * Get all media files by type + * Get all media files by type name * - * @param null|int $type Media type + * @param string $type Media type * - * @return Media[] + * @return Media * * @since 1.0.0 */ - public function getFilesByType(int $type = null) : array + public function getFileByTypeName(string $type) : Media { - $files = []; foreach ($this->files as $file) { - if ($file->type === $type) { - $files[] = $file; + if ($file->hasMediaTypeName($type)) { + return $file; } } - return $files; + return new NullMedia(); } /** diff --git a/Models/EmployeeHistoryMapper.php b/Models/EmployeeHistoryMapper.php index 766307d..2bd5c40 100755 --- a/Models/EmployeeHistoryMapper.php +++ b/Models/EmployeeHistoryMapper.php @@ -49,7 +49,7 @@ final class EmployeeHistoryMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -74,7 +74,7 @@ final class EmployeeHistoryMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/Models/EmployeeMapper.php b/Models/EmployeeMapper.php index 953d3e4..c65ffe4 100755 --- a/Models/EmployeeMapper.php +++ b/Models/EmployeeMapper.php @@ -44,7 +44,7 @@ final class EmployeeMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -57,7 +57,7 @@ final class EmployeeMapper extends DataMapperFactory /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ @@ -70,7 +70,7 @@ final class EmployeeMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/Models/EmployeeWorkHistory.php b/Models/EmployeeWorkHistory.php index f641085..7cbc12d 100755 --- a/Models/EmployeeWorkHistory.php +++ b/Models/EmployeeWorkHistory.php @@ -113,16 +113,16 @@ class EmployeeWorkHistory implements \JsonSerializable /** * Get media file by type * - * @param null|int $type Media type + * @param int $type Media type * * @return Media * * @since 1.0.0 */ - public function getFileByType(int $type = null) : Media + public function getFileByType(int $type) : Media { foreach ($this->files as $file) { - if ($file->type === $type) { + if ($file->hasMediaTypeId($type)) { return $file; } } @@ -131,24 +131,23 @@ class EmployeeWorkHistory implements \JsonSerializable } /** - * Get all media files by type + * Get all media files by type name * - * @param null|int $type Media type + * @param string $type Media type * - * @return Media[] + * @return Media * * @since 1.0.0 */ - public function getFilesByType(int $type = null) : array + public function getFileByTypeName(string $type) : Media { - $files = []; foreach ($this->files as $file) { - if ($file->type === $type) { - $files[] = $file; + if ($file->hasMediaTypeName($type)) { + return $file; } } - return $files; + return new NullMedia(); } /** diff --git a/Models/EmployeeWorkHistoryMapper.php b/Models/EmployeeWorkHistoryMapper.php index b851c66..462bdaa 100755 --- a/Models/EmployeeWorkHistoryMapper.php +++ b/Models/EmployeeWorkHistoryMapper.php @@ -45,7 +45,7 @@ final class EmployeeWorkHistoryMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -58,7 +58,7 @@ final class EmployeeWorkHistoryMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [