From cb0f6c1f4976191834ccf8ea92087f6e679ceb59 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 9 Apr 2023 06:03:39 +0200 Subject: [PATCH] fix static analysis --- Controller/ApiController.php | 56 ++++--- Controller/BackendController.php | 6 +- Models/AttributeValueType.php | 40 ----- Models/Client.php | 50 +----- Models/ClientAttribute.php | 102 ------------ Models/ClientAttributeMapper.php | 19 ++- Models/ClientAttributeType.php | 210 ----------------------- Models/ClientAttributeTypeMapper.php | 9 + Models/ClientAttributeValue.php | 230 -------------------------- Models/ClientAttributeValueMapper.php | 9 + Models/NullClientAttribute.php | 47 ------ Models/NullClientAttributeType.php | 46 ------ Models/NullClientAttributeValue.php | 46 ------ 13 files changed, 72 insertions(+), 798 deletions(-) delete mode 100755 Models/AttributeValueType.php delete mode 100755 Models/ClientAttribute.php delete mode 100755 Models/ClientAttributeType.php delete mode 100755 Models/ClientAttributeValue.php delete mode 100755 Models/NullClientAttribute.php delete mode 100755 Models/NullClientAttributeType.php delete mode 100755 Models/NullClientAttributeValue.php diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 25b211b..3e5bd3c 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -18,15 +18,17 @@ use Modules\Admin\Models\Account; use Modules\Admin\Models\Address; use Modules\Admin\Models\AddressMapper; use Modules\Admin\Models\NullAccount; +use Modules\Attribute\Models\Attribute; +use Modules\Attribute\Models\AttributeType; +use Modules\Attribute\Models\AttributeValue; +use Modules\Attribute\Models\NullAttributeType; +use Modules\Attribute\Models\NullAttributeValue; use Modules\Auditor\Models\Audit; use Modules\Auditor\Models\AuditMapper; use Modules\ClientManagement\Models\Client; -use Modules\ClientManagement\Models\ClientAttribute; use Modules\ClientManagement\Models\ClientAttributeMapper; -use Modules\ClientManagement\Models\ClientAttributeType; use Modules\ClientManagement\Models\ClientAttributeTypeL11nMapper; use Modules\ClientManagement\Models\ClientAttributeTypeMapper; -use Modules\ClientManagement\Models\ClientAttributeValue; use Modules\ClientManagement\Models\ClientAttributeValueL11nMapper; use Modules\ClientManagement\Models\ClientAttributeValueMapper; use Modules\ClientManagement\Models\ClientL11n; @@ -34,8 +36,7 @@ use Modules\ClientManagement\Models\ClientL11nMapper; use Modules\ClientManagement\Models\ClientL11nType; use Modules\ClientManagement\Models\ClientL11nTypeMapper; use Modules\ClientManagement\Models\ClientMapper; -use Modules\ClientManagement\Models\NullClientAttributeType; -use Modules\ClientManagement\Models\NullClientAttributeValue; +use Modules\ClientManagement\Models\NullClient; use Modules\ClientManagement\Models\NullClientL11nType; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\PathSettings; @@ -65,6 +66,16 @@ use phpOMS\Utils\StringUtils; */ final class ApiController extends Controller { + /** + * Find client by account + * + * @param int $account Account id + * @param int $unit Unit id + * + * @return null|Client + * + * @since 1.0.0 + */ public function findClientForAccount(int $account, int $unit = null) : ?Client { $clientMapper = ClientMapper::get() @@ -77,7 +88,7 @@ final class ApiController extends Controller /** @var \Modules\ClientManagement\Models\Client $client */ $client = $clientMapper->execute(); - return $client instanceof NullAccount ? null : $client; + return $client instanceof NullClient ? null : $client; } /** @@ -117,8 +128,8 @@ final class ApiController extends Controller if (\in_array($client->mainAddress->getCountry(), ISO3166CharEnum::getRegion('eu'))) { $validate = EUVATVies::validateQualified( + $request->getDataString('vat_id') ?? '', $unit->getAttribute('vat_id')?->value->getValue() ?? '', - $request->getData('vat_id'), $client->account->name1, $client->mainAddress->city, $client->mainAddress->postal, @@ -146,7 +157,7 @@ final class ApiController extends Controller && $validate['city'] === true) || $validate['status'] !== 0 // Api out of order -> accept it -> @todo: test it during invoice creation ) { - /** @var \Modules\ClientManagement\Models\ClientAttributeType $type */ + /** @var \Modules\Attribute\Models\AttributeType $type */ $type = ClientAttributeTypeMapper::get()->where('name', 'vat_id')->execute(); $internalRequest = new HttpRequest(new HttpUri('')); @@ -169,7 +180,7 @@ final class ApiController extends Controller ->where('id', $this->app->unitId) ->execute(); - /** @var \Modules\ClientManagement\Models\ClientAttributeType $type */ + /** @var \Modules\Attribute\Models\AttributeType $type */ $type = ClientAttributeTypeMapper::get() ->where('name', 'sales_tax_code') ->execute(); @@ -283,6 +294,7 @@ final class ApiController extends Controller ->where('unit', $request->getDataInt('unit')); } + /** @var \Modules\ClientManagement\Models\Client $client */ $client = $clientMapper->execute(); $old = $client->mainAddress; @@ -508,18 +520,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ClientAttribute + * @return Attribute * * @since 1.0.0 */ - private function createClientAttributeFromRequest(RequestAbstract $request) : ClientAttribute + private function createClientAttributeFromRequest(RequestAbstract $request) : Attribute { - $attribute = new ClientAttribute(); - $attribute->client = (int) $request->getData('client'); - $attribute->type = new NullClientAttributeType((int) $request->getData('type')); + $attribute = new Attribute(); + $attribute->ref = (int) $request->getData('client'); + $attribute->type = new NullAttributeType((int) $request->getData('type')); if ($request->hasData('value')) { - $attribute->value = new NullClientAttributeValue((int) $request->getData('value')); + $attribute->value = new NullAttributeValue((int) $request->getData('value')); } else { $newRequest = clone $request; $newRequest->setData('value', $request->getData('custom'), true); @@ -656,13 +668,13 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ClientAttributeType + * @return AttributeType * * @since 1.0.0 */ - private function createClientAttributeTypeFromRequest(RequestAbstract $request) : ClientAttributeType + private function createClientAttributeTypeFromRequest(RequestAbstract $request) : AttributeType { - $attrType = new ClientAttributeType($request->getDataString('name') ?? ''); + $attrType = new AttributeType($request->getDataString('name') ?? ''); $attrType->datatype = $request->getDataInt('datatype') ?? 0; $attrType->custom = $request->getDataBool('custom') ?? false; $attrType->isRequired = (bool) ($request->getData('is_required') ?? false); @@ -736,18 +748,18 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ClientAttributeValue + * @return AttributeValue * * @since 1.0.0 */ - private function createClientAttributeValueFromRequest(RequestAbstract $request) : ClientAttributeValue + private function createClientAttributeValueFromRequest(RequestAbstract $request) : AttributeValue { - /** @var ClientAttributeType $type */ + /** @var AttributeType $type */ $type = ClientAttributeTypeMapper::get() ->where('id', $request->getDataInt('type') ?? 0) ->execute(); - $attrValue = new ClientAttributeValue(); + $attrValue = new AttributeValue(); $attrValue->isDefault = $request->getDataBool('default') ?? false; $attrValue->setValue($request->getData('value'), $type->datatype); diff --git a/Controller/BackendController.php b/Controller/BackendController.php index d8ef579..28387a1 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -58,7 +58,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/ClientManagement/Theme/Backend/attribute-type-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\ClientManagement\Models\ClientAttributeType[] $attributes */ + /** @var \Modules\Attribute\Models\AttributeType[] $attributes */ $attributes = ClientAttributeTypeMapper::getAll() ->with('l11n') ->where('l11n/language', $response->getLanguage()) @@ -87,7 +87,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/ClientManagement/Theme/Backend/attribute-value-list'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\ClientManagement\Models\ClientAttributeValue[] $attributes */ + /** @var \Modules\Attribute\Models\AttributeValue[] $attributes */ $attributes = ClientAttributeValueMapper::getAll() ->with('l11n') ->where('l11n/language', $response->getLanguage()) @@ -116,7 +116,7 @@ final class BackendController extends Controller $view->setTemplate('/Modules/ClientManagement/Theme/Backend/attribute-type'); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); - /** @var \Modules\ClientManagement\Models\ClientAttributeType $attribute */ + /** @var \Modules\Attribute\Models\AttributeType $attribute */ $attribute = ClientAttributeTypeMapper::get() ->with('l11n') ->where('id', (int) $request->getData('id')) diff --git a/Models/AttributeValueType.php b/Models/AttributeValueType.php deleted file mode 100755 index 1411fb1..0000000 --- a/Models/AttributeValueType.php +++ /dev/null @@ -1,40 +0,0 @@ -partners; } - /** - * Add attribute to client - * - * @param ClientAttribute $attribute Attribute - * - * @return void - * - * @since 1.0.0 - */ - public function addAttribute(ClientAttribute $attribute) : void - { - $this->attributes[] = $attribute; - } - - /** - * Get attributes - * - * @return ClientAttribute[] - * - * @since 1.0.0 - */ - public function getAttributes() : array - { - return $this->attributes; - } - - /** - * Get attribute - * - * @param string $attrName Attribute name - * - * @return null|ClientAttribute - * - * @since 1.0.0 - */ - public function getAttribute(string $attrName) : ?ClientAttribute - { - foreach ($this->attributes as $attribute) { - if ($attribute->type->name === $attrName) { - return $attribute; - } - } - - return null; - } - /** * Get payments * @@ -478,4 +432,6 @@ class Client { return $this->toArray(); } + + use \Modules\Attribute\Models\AttributeHolderTrait; } diff --git a/Models/ClientAttribute.php b/Models/ClientAttribute.php deleted file mode 100755 index 27d6f2d..0000000 --- a/Models/ClientAttribute.php +++ /dev/null @@ -1,102 +0,0 @@ -type = new ClientAttributeType(); - $this->value = new ClientAttributeValue(); - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'client' => $this->client, - 'type' => $this->type, - 'value' => $this->value, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/ClientAttributeMapper.php b/Models/ClientAttributeMapper.php index 29d3eaf..e979d41 100755 --- a/Models/ClientAttributeMapper.php +++ b/Models/ClientAttributeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\ClientManagement\Models; +use Modules\Attribute\Models\Attribute; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -34,7 +35,7 @@ final class ClientAttributeMapper extends DataMapperFactory */ public const COLUMNS = [ 'clientmgmt_client_attr_id' => ['name' => 'clientmgmt_client_attr_id', 'type' => 'int', 'internal' => 'id'], - 'clientmgmt_client_attr_client' => ['name' => 'clientmgmt_client_attr_client', 'type' => 'int', 'internal' => 'client'], + 'clientmgmt_client_attr_client' => ['name' => 'clientmgmt_client_attr_client', 'type' => 'int', 'internal' => 'ref'], 'clientmgmt_client_attr_type' => ['name' => 'clientmgmt_client_attr_type', 'type' => 'int', 'internal' => 'type'], 'clientmgmt_client_attr_value' => ['name' => 'clientmgmt_client_attr_value', 'type' => 'int', 'internal' => 'value'], ]; @@ -47,15 +48,23 @@ final class ClientAttributeMapper extends DataMapperFactory */ public const OWNS_ONE = [ 'type' => [ - 'mapper' => ClientAttributeTypeMapper::class, - 'external' => 'clientmgmt_client_attr_type', + 'mapper' => ClientAttributeTypeMapper::class, + 'external' => 'clientmgmt_client_attr_type', ], 'value' => [ - 'mapper' => ClientAttributeValueMapper::class, - 'external' => 'clientmgmt_client_attr_value', + 'mapper' => ClientAttributeValueMapper::class, + 'external' => 'clientmgmt_client_attr_value', ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Attribute::class; + /** * Primary table. * diff --git a/Models/ClientAttributeType.php b/Models/ClientAttributeType.php deleted file mode 100755 index e16f421..0000000 --- a/Models/ClientAttributeType.php +++ /dev/null @@ -1,210 +0,0 @@ -name = $name; - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - public function getDefaultByValue(mixed $value) : ClientAttributeValue - { - foreach ($this->defaults as $default) { - if ($default->getValue() === $value) { - return $default; - } - } - - return new NullClientAttributeValue(); - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set fields - * - * @param int $fields Fields - * - * @return void - * - * @since 1.0.0 - */ - public function setFields(int $fields) : void - { - $this->fields = $fields; - } - - /** - * Get default values - * - * @return array - * - * @sicne 1.0.0 - */ - public function getDefaults() : array - { - return $this->defaults; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'fields' => $this->fields, - 'custom' => $this->custom, - 'validationPattern' => $this->validationPattern, - 'isRequired' => $this->isRequired, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/ClientAttributeTypeMapper.php b/Models/ClientAttributeTypeMapper.php index 1f6492b..5a4ac1f 100755 --- a/Models/ClientAttributeTypeMapper.php +++ b/Models/ClientAttributeTypeMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\ClientManagement\Models; +use Modules\Attribute\Models\AttributeType; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -64,6 +65,14 @@ final class ClientAttributeTypeMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeType::class; + /** * Primary table. * diff --git a/Models/ClientAttributeValue.php b/Models/ClientAttributeValue.php deleted file mode 100755 index cec91bb..0000000 --- a/Models/ClientAttributeValue.php +++ /dev/null @@ -1,230 +0,0 @@ -id; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->ref = $this->id; - $this->l11n->setLanguage($lang); - } - } - - /** - * Get localization - * - * @return null|string - * - * @since 1.0.0 - */ - public function getL11n() : ?string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * Set value - * - * @param int|string|float $value Value - * @param int $datatype Datatype - * - * @return void - * - * @since 1.0.0 - */ - public function setValue(mixed $value, int $datatype) : void - { - if ($datatype === AttributeValueType::_STRING) { - $this->valueStr = (string) $value; - } elseif ($datatype === AttributeValueType::_INT - || $datatype === AttributeValueType::_FLOAT_INT - || $datatype === AttributeValueType::_BOOL - ) { - $this->valueInt = (int) $value; - } elseif ($datatype === AttributeValueType::_FLOAT) { - $this->valueDec = (float) $value; - } elseif ($datatype === AttributeValueType::_DATETIME) { - $this->valueDat = new \DateTime((string) $value); - } - } - - /** - * Get value - * - * @return null|int|string|float|\DateTimeInterface - * - * @since 1.0.0 - */ - public function getValue() : mixed - { - if (!empty($this->valueStr)) { - return $this->valueStr; - } elseif (!empty($this->valueInt)) { - return $this->valueInt; - } elseif (!empty($this->valueDec)) { - return $this->valueDec; - } elseif ($this->valueDat instanceof \DateTimeInterface) { - return $this->valueDat; - } - - return null; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'valueInt' => $this->valueInt, - 'valueStr' => $this->valueStr, - 'valueDec' => $this->valueDec, - 'valueDat' => $this->valueDat, - 'isDefault' => $this->isDefault, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/ClientAttributeValueMapper.php b/Models/ClientAttributeValueMapper.php index 04e4f0e..69fafcd 100755 --- a/Models/ClientAttributeValueMapper.php +++ b/Models/ClientAttributeValueMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\ClientManagement\Models; +use Modules\Attribute\Models\AttributeValue; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; /** @@ -59,6 +60,14 @@ final class ClientAttributeValueMapper extends DataMapperFactory ], ]; + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = AttributeValue::class; + /** * Primary table. * diff --git a/Models/NullClientAttribute.php b/Models/NullClientAttribute.php deleted file mode 100755 index faec555..0000000 --- a/Models/NullClientAttribute.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullClientAttributeType.php b/Models/NullClientAttributeType.php deleted file mode 100755 index 0f4f0bb..0000000 --- a/Models/NullClientAttributeType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/NullClientAttributeValue.php b/Models/NullClientAttributeValue.php deleted file mode 100755 index bf6f2f9..0000000 --- a/Models/NullClientAttributeValue.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -}