From 6faa514311844ecf935260edaaa680cd7fb8937f 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 --- Admin/Install/db.json | 5 ---- Controller/ApiController.php | 30 ++++++++++++--------- Models/AccountRelationMapper.php | 2 +- Models/GroupRelationMapper.php | 2 +- Models/Task.php | 12 ++++----- Models/TaskAttributeMapper.php | 2 +- Models/TaskAttributeType.php | 36 +++++++++++++++++-------- Models/TaskAttributeTypeL11nMapper.php | 2 +- Models/TaskAttributeTypeMapper.php | 2 +- Models/TaskAttributeValue.php | 13 ++++----- Models/TaskAttributeValueL11nMapper.php | 3 ++- Models/TaskAttributeValueMapper.php | 2 +- Models/TaskElementMapper.php | 4 +-- Models/TaskMapper.php | 6 ++--- Models/TaskSeenMapper.php | 2 +- 15 files changed, 70 insertions(+), 53 deletions(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 0d53712..fb4feca 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -189,11 +189,6 @@ "type": "TINYINT(1)", "null": false }, - "task_attr_value_valuetype": { - "name": "task_attr_value_valuetype", - "type": "INT(11)", - "null": false - }, "task_attr_value_valueStr": { "name": "task_attr_value_valueStr", "type": "VARCHAR(255)", diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 9243ba2..ea9c6f6 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -41,6 +41,8 @@ use Modules\Tasks\Models\TaskElementMapper; use Modules\Tasks\Models\TaskMapper; use Modules\Tasks\Models\TaskStatus; use Modules\Tasks\Models\TaskType; +use phpOMS\Localization\BaseStringL11n; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; @@ -788,18 +790,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return TaskAttributeTypeL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createTaskAttributeTypeL11nFromRequest(RequestAbstract $request) : TaskAttributeTypeL11n + private function createTaskAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $attrL11n = new TaskAttributeTypeL11n(); - $attrL11n->type = (int) ($request->getData('type') ?? 0); + $attrL11n = new BaseStringL11n(); + $attrL11n->ref = (int) ($request->getData('type') ?? 0); $attrL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $attrL11n->title = (string) ($request->getData('title') ?? ''); + $attrL11n->content = (string) ($request->getData('title') ?? ''); return $attrL11n; } @@ -943,10 +945,14 @@ final class ApiController extends Controller */ private function createTaskAttributeValueFromRequest(RequestAbstract $request) : TaskAttributeValue { - $type = (int) ($request->getData('attributetype') ?? 0); + /** @var TaskAttributeType $type */ + $type = TaskAttributeTypeMapper::get() + ->where('id', (int) ($request->getData('type') ?? 0)) + ->execute(); - $attrValue = new TaskAttributeValue($type, $request->getData('value')); + $attrValue = new TaskAttributeValue(); $attrValue->isDefault = (bool) ($request->getData('default') ?? false); + $attrValue->setValue($request->getData('value'), $type->datatype); if ($request->getData('title') !== null) { $attrValue->setL11n($request->getData('title'), $request->getData('language') ?? ISO639x1Enum::_EN); @@ -1008,18 +1014,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return TaskAttributeValueL11n + * @return BaseStringL11n * * @since 1.0.0 */ - private function createTaskAttributeValueL11nFromRequest(RequestAbstract $request) : TaskAttributeValueL11n + private function createTaskAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n { - $attrL11n = new TaskAttributeValueL11n(); - $attrL11n->value = (int) ($request->getData('value') ?? 0); + $attrL11n = new BaseStringL11n(); + $attrL11n->ref = (int) ($request->getData('value') ?? 0); $attrL11n->setLanguage((string) ( $request->getData('language') ?? $request->getLanguage() )); - $attrL11n->title = (string) ($request->getData('title') ?? ''); + $attrL11n->content = (string) ($request->getData('title') ?? ''); return $attrL11n; } diff --git a/Models/AccountRelationMapper.php b/Models/AccountRelationMapper.php index 70de154..7942a5d 100755 --- a/Models/AccountRelationMapper.php +++ b/Models/AccountRelationMapper.php @@ -43,7 +43,7 @@ final class AccountRelationMapper extends DataMapperFactory /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ diff --git a/Models/GroupRelationMapper.php b/Models/GroupRelationMapper.php index cdac2e6..d44929b 100755 --- a/Models/GroupRelationMapper.php +++ b/Models/GroupRelationMapper.php @@ -43,7 +43,7 @@ final class GroupRelationMapper extends DataMapperFactory /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ diff --git a/Models/Task.php b/Models/Task.php index 4f68c08..ec2fb82 100755 --- a/Models/Task.php +++ b/Models/Task.php @@ -127,7 +127,7 @@ class Task implements \JsonSerializable /** * Attributes. * - * @var ItemAttribute[] + * @var TaskAttribute[] * @since 1.0.0 */ private array $attributes = []; @@ -613,13 +613,13 @@ class Task implements \JsonSerializable /** * Add attribute to item * - * @param ItemAttribute $attribute Note + * @param TaskAttribute $attribute Note * * @return void * * @since 1.0.0 */ - public function addAttribute(ItemAttribute $attribute) : void + public function addAttribute(TaskAttribute $attribute) : void { $this->attributes[] = $attribute; } @@ -627,7 +627,7 @@ class Task implements \JsonSerializable /** * Get attributes * - * @return ItemAttribute[] + * @return TaskAttribute[] * * @since 1.0.0 */ @@ -662,11 +662,11 @@ class Task implements \JsonSerializable * * @param string $attrName Attribute name * - * @return null|AttributeValue + * @return null|TaskAttributeValue * * @since 1.0.0 */ - public function getAttribute(string $attrName) : ?AttributeValue + public function getAttribute(string $attrName) : ?TaskAttributeValue { foreach ($this->attributes as $attribute) { if ($attribute->type->name === $attrName) { diff --git a/Models/TaskAttributeMapper.php b/Models/TaskAttributeMapper.php index f00db04..e0cd3e3 100755 --- a/Models/TaskAttributeMapper.php +++ b/Models/TaskAttributeMapper.php @@ -42,7 +42,7 @@ final class TaskAttributeMapper extends DataMapperFactory /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ diff --git a/Models/TaskAttributeType.php b/Models/TaskAttributeType.php index e944257..52ba31b 100755 --- a/Models/TaskAttributeType.php +++ b/Models/TaskAttributeType.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Tasks\Models; +use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO639x1Enum; /** @@ -62,12 +63,20 @@ class TaskAttributeType implements \JsonSerializable public bool $isRequired = false; + /** + * Datatype of the attribute + * + * @var int + * @since 1.0.0 + */ + public int $datatype = AttributeValueType::_STRING; + /** * Localization * - * @var TaskAttributeTypeL11n + * @var BaseStringL11n */ - private string | TaskAttributeTypeL11n $l11n = ''; + private string | BaseStringL11n $l11n = ''; /** * Possible default attribute values @@ -111,22 +120,23 @@ class TaskAttributeType implements \JsonSerializable /** * Set l11n * - * @param string|TaskAttributeTypeL11n $l11n Tag article l11n - * @param string $lang Language + * @param string|BaseStringL11n $l11n Tag article l11n + * @param string $lang Language * * @return void * * @since 1.0.0 */ - public function setL11n(string | TaskAttributeTypeL11n $l11n, string $lang = ISO639x1Enum::_EN) : void + public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void { - if ($l11n instanceof TaskAttributeTypeL11n) { + if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof TaskAttributeTypeL11n) { - $this->l11n->title = $l11n; + } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { + $this->l11n->content = $l11n; + $this->l11n->setLanguage($lang); } else { - $this->l11n = new TaskAttributeTypeL11n(); - $this->l11n->title = $l11n; + $this->l11n = new BaseStringL11n(); + $this->l11n->content = $l11n; $this->l11n->setLanguage($lang); } } @@ -138,7 +148,11 @@ class TaskAttributeType implements \JsonSerializable */ public function getL11n() : string { - return $this->l11n instanceof TaskAttributeTypeL11n ? $this->l11n->title : $this->l11n; + if (!isset($this->l11n)) { + return ''; + } + + return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; } /** diff --git a/Models/TaskAttributeTypeL11nMapper.php b/Models/TaskAttributeTypeL11nMapper.php index 41a7612..59a78fc 100755 --- a/Models/TaskAttributeTypeL11nMapper.php +++ b/Models/TaskAttributeTypeL11nMapper.php @@ -59,7 +59,7 @@ final class TaskAttributeTypeL11nMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = BaseStringL11n::class; diff --git a/Models/TaskAttributeTypeMapper.php b/Models/TaskAttributeTypeMapper.php index a539cd0..7df6268 100755 --- a/Models/TaskAttributeTypeMapper.php +++ b/Models/TaskAttributeTypeMapper.php @@ -44,7 +44,7 @@ final class TaskAttributeTypeMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/Models/TaskAttributeValue.php b/Models/TaskAttributeValue.php index b3a5ed5..df2dbc0 100755 --- a/Models/TaskAttributeValue.php +++ b/Models/TaskAttributeValue.php @@ -124,7 +124,7 @@ class TaskAttributeValue implements \JsonSerializable * Set l11n * * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language + * @param string $lang Language * * @return void * @@ -135,11 +135,12 @@ class TaskAttributeValue implements \JsonSerializable if ($l11n instanceof BaseStringL11n) { $this->l11n = $l11n; } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; + $this->l11n->content = $l11n; + $this->l11n->setLanguage($lang); } else { - $this->l11n = new BaseStringL11n(); + $this->l11n = new BaseStringL11n(); $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; + $this->l11n->ref = $this->id; $this->l11n->setLanguage($lang); } } @@ -159,7 +160,7 @@ class TaskAttributeValue implements \JsonSerializable /** * Set value * - * @param int|string|float|\DateTimeInterface $value Value + * @param int|string|float $value Value * * @return void * @@ -177,7 +178,7 @@ class TaskAttributeValue implements \JsonSerializable } elseif ($datatype === AttributeValueType::_FLOAT) { $this->valueDec = (float) $value; } elseif ($datatype === AttributeValueType::_DATETIME) { - $this->valueDat = new \DateTime($value); + $this->valueDat = new \DateTime((string) $value); } } diff --git a/Models/TaskAttributeValueL11nMapper.php b/Models/TaskAttributeValueL11nMapper.php index 1827ab1..8dd1522 100755 --- a/Models/TaskAttributeValueL11nMapper.php +++ b/Models/TaskAttributeValueL11nMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\Tasks\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11n; /** * Task mapper class. @@ -58,7 +59,7 @@ final class TaskAttributeValueL11nMapper extends DataMapperFactory /** * Model to use by the mapper. * - * @var string + * @var class-string * @since 1.0.0 */ public const MODEL = BaseStringL11n::class; diff --git a/Models/TaskAttributeValueMapper.php b/Models/TaskAttributeValueMapper.php index e149ff1..6efe1fe 100755 --- a/Models/TaskAttributeValueMapper.php +++ b/Models/TaskAttributeValueMapper.php @@ -45,7 +45,7 @@ final class TaskAttributeValueMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ diff --git a/Models/TaskElementMapper.php b/Models/TaskElementMapper.php index e09f59f..f1e2d67 100755 --- a/Models/TaskElementMapper.php +++ b/Models/TaskElementMapper.php @@ -49,7 +49,7 @@ final class TaskElementMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ @@ -76,7 +76,7 @@ final class TaskElementMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ diff --git a/Models/TaskMapper.php b/Models/TaskMapper.php index 3209499..38c8391 100755 --- a/Models/TaskMapper.php +++ b/Models/TaskMapper.php @@ -63,7 +63,7 @@ final class TaskMapper extends DataMapperFactory /** * Has many relation. * - * @var array + * @var array * @since 1.0.0 */ public const HAS_MANY = [ @@ -96,7 +96,7 @@ final class TaskMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [ @@ -109,7 +109,7 @@ final class TaskMapper extends DataMapperFactory /** * Has one relation. * - * @var array + * @var array * @since 1.0.0 */ public const OWNS_ONE = [ diff --git a/Models/TaskSeenMapper.php b/Models/TaskSeenMapper.php index a811de9..5a14bf1 100755 --- a/Models/TaskSeenMapper.php +++ b/Models/TaskSeenMapper.php @@ -49,7 +49,7 @@ final class TaskSeenMapper extends DataMapperFactory /** * Belongs to. * - * @var array + * @var array * @since 1.0.0 */ public const BELONGS_TO = [