cs and phpstan fixes

This commit is contained in:
Dennis Eichhorn 2020-10-24 17:52:23 +02:00
parent a398e94db7
commit 10e4ee2eca
15 changed files with 312 additions and 90 deletions

View File

@ -47,6 +47,13 @@ final class Installer extends InstallerAbstract
self::createItemAttributeValues($attrTypes);
}
/**
* Install default attribute types
*
* @return ItemAttributeType[]
*
* @since 1.0.0
*/
private static function createItemAttributeTypes() : array
{
$itemAttrType = [];
@ -59,6 +66,15 @@ final class Installer extends InstallerAbstract
return $itemAttrType;
}
/**
* Create default attribute values for types
*
* @param ItemAttributeType[] $itemAttrType Attribute types
*
* @return array<string, ItemAttributeValue[]>
*
* @since 1.0.0
*/
private static function createItemAttributeValues(array $itemAttrType) : array
{
$itemAttrValue = [];
@ -110,6 +126,6 @@ final class Installer extends InstallerAbstract
$itemAttrValue['color'][] = new ItemAttributeValue($id, 'Grau', ISO639x1Enum::_DE);
ItemAttributeValueMapper::create($itemAttrValue['color'][21]);
return $itemAttrType;
return $itemAttrValue;
}
}

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace Modules\ItemManagement\Models;
use Modules\Media\Models\NullMedia;
use Modules\Media\Models\Media;
/**
* Account class.
@ -34,25 +35,41 @@ class Item
*/
protected int $id = 0;
private $number = '';
private $articleGroup = 0;
private $salesGroup = 0;
private $productGroup = 0;
private $segment = 0;
/**
* Item number/id
*
* @var string
* @since 1.0.0
*/
private string $number = '';
private $successor = 0;
private int $type = 0;
private $files = [];
/**
* Files.
*
* @var int[]|Media[]
* @since 1.0.0
*/
private array $files = [];
private $l11n = [];
/**
* Localizations.
*
* @var int[]|ItemL11n[]
* @since 1.0.0
*/
private array $l11n = [];
private $attributes = [];
/**
* Attributes.
*
* @var int[]|ItemAttribute[]
* @since 1.0.0
*/
private array $attributes = [];
private $partslist = null;
@ -60,7 +77,13 @@ class Item
private $disposal = null;
private $createdAt = null;
/**
* Created at.
*
* @var \DateTimeImmutable
* @since 1.0.0
*/
private \DateTimeImmutable $createdAt;
private $info = '';
@ -182,12 +205,30 @@ class Item
return new NullItemL11n();
}
/**
* Add media to item
*
* @param int|Media $media Media
*
* @return void
*
* @since 1.0.0
*/
public function addFile($media) : void
{
$this->files[] = $media;
}
public function getFileByType(string $type)
/**
* Get media file by type
*
* @param string $type Media type
*
* @return Media
*
* @since 1.0.0
*/
public function getFileByType(string $type) : Media
{
foreach ($this->files as $file) {
if ($file->getType() === $type) {
@ -198,6 +239,15 @@ class Item
return new NullMedia();
}
/**
* Get all media files by type
*
* @param string $type Media type
*
* @return Media[]
*
* @since 1.0.0
*/
public function getFilesByType(string $type) : array
{
$files = [];

View File

@ -26,12 +26,36 @@ use phpOMS\Contract\ArrayableInterface;
*/
class ItemAttribute implements \JsonSerializable, ArrayableInterface
{
/**
* Id.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
protected $item = 0;
/**
* Item this attribute belongs to
*
* @var int
* @since 1.0.0
*/
protected int $item = 0;
/**
* Attribute type the attribute belongs to
*
* @var int|ItemAttributeType
* @since 1.0.0
*/
protected $type = 0;
/**
* Attribute value the attribute belongs to
*
* @var int|ItemAttributeValue
* @since 1.0.0
*/
protected $value = 0;
/**

View File

@ -44,7 +44,7 @@ final class ItemAttributeMapper extends DataMapperAbstract
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
protected static array $ownsOne = [

View File

@ -17,7 +17,7 @@ namespace Modules\ItemManagement\Models;
use phpOMS\Contract\ArrayableInterface;
/**
* Item class.
* Item Attribute Type class.
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
@ -26,16 +26,52 @@ use phpOMS\Contract\ArrayableInterface;
*/
class ItemAttributeType implements \JsonSerializable, ArrayableInterface
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
protected string $name = '';
protected $fields = 0;
/**
* Which field data type is required (string, int, ...) in the value
*
* @var int
* @since 1.0.0
*/
protected int $fields = 0;
/**
* Is a custom value allowed (e.g. custom string)
*
* @var bool
* @since 1.0.0
*/
protected bool $custom = false;
/**
* Localization
*
* @var int|int[]|ItemAttributeTypeL11n|ItemAttributeTypeL11n[]
*/
protected $l11n = 0;
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->name = $name;

View File

@ -28,7 +28,7 @@ use phpOMS\Localization\ISO639x1Enum;
class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
{
/**
* Article ID.
* ID.
*
* @var int
* @since 1.0.0
@ -62,15 +62,17 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
/**
* Constructor.
*
* @param string $description Title
* @param int|ItemL11nType $type Attribute type
* @param string $title Localized title
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct($type = 0, string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type;
$this->title = $title;
$this->language = $language;
$this->type = $type;
$this->title = $title;
$this->language = $language;
}
/**
@ -85,6 +87,44 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
return $this->id;
}
/**
* Get attribute type
*
* @return int|ItemL11nType
*
* @since 1.0.0
*/
public function getType()
{
return $this->type;
}
/**
* Get attribute title
*
* @return string
*
* @since 1.0.0
*/
public function getTitle() : string
{
return $this->title;
}
/**
* Set title
*
* @param string $title Title
*
* @return void
*
* @since 1.0.0
*/
public function setTitle(string $title) : void
{
$this->title = $title;
}
/**
* {@inheritdoc}
*/

View File

@ -45,7 +45,7 @@ final class ItemAttributeTypeL11nMapper extends DataMapperAbstract
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
protected static array $ownsOne = [

View File

@ -23,8 +23,6 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*
* @todo Do I really want to create a relation to the language mapper? It's not really needed right?
*/
final class ItemAttributeTypeMapper extends DataMapperAbstract
{

View File

@ -19,7 +19,7 @@ use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
/**
* Item class.
* Item attribute value class.
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
@ -28,34 +28,90 @@ use phpOMS\Localization\ISO639x1Enum;
*/
class ItemAttributeValue implements \JsonSerializable, ArrayableInterface
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
protected $type = 0;
/**
* Type of the attribute
*
* @var int
* @since 1.0.0
*/
protected int $type = 0;
/**
* Int value
*
* @var null|int
* @since 1.0.0
*/
protected ?int $valueInt = null;
/**
* String value
*
* @var null|string
* @since 1.0.0
*/
protected ?string $valueStr = null;
/**
* Decimal value
*
* @var null|float
* @since 1.0.0
*/
protected ?float $valueDec = null;
protected ?\DateTime $valueDat = null;
/**
* DateTime value
*
* @var null|\DateTimeInterface
* @since 1.0.0
*/
protected ?\DateTimeInterface $valueDat = null;
/**
* Is a default value which can be selected
*
* @var bool
* @since 1.0.0
*/
protected bool $isDefault = false;
/**
* Language
*
* @var string
* @since 1.0.0
*/
protected string $language = ISO639x1Enum::_EN;
/**
* Country
*
* @var string
* @since 1.0.0
*/
protected string $country = ISO3166TwoEnum::_USA;
/**
* Constructor.
*
* @param string $description Title
* @param int $type Type
* @param mixed $value Value
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct($type = 0, $value = '', string $language = ISO639x1Enum::_EN)
public function __construct(int $type = 0, $value = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type;
$this->type = $type;
if (\is_string($value)) {
$this->valueStr = $value;
@ -67,7 +123,7 @@ class ItemAttributeValue implements \JsonSerializable, ArrayableInterface
$this->valueDat = $value;
}
$this->language = $language;
$this->language = $language;
}
/**

View File

@ -8,7 +8,7 @@
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
* @link https: //orange-management.org
*/
declare(strict_types=1);
@ -23,7 +23,7 @@ use phpOMS\Localization\Defaults\LanguageMapper;
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
* @link https://orange-management.org
* @link https: //orange-management.org
* @since 1.0.0
*
* @todo Do I really want to create a relation to the language mapper? It's not really needed right?
@ -37,37 +37,37 @@ final class ItemAttributeValueMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static array $columns = [
'itemmgmt_attr_value_id' => ['name' => 'itemmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_attr_value_default' => ['name' => 'itemmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'itemmgmt_attr_value_type' => ['name' => 'itemmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'],
'itemmgmt_attr_value_valueStr' => ['name' => 'itemmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'],
'itemmgmt_attr_value_id' => ['name' => 'itemmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_attr_value_default' => ['name' => 'itemmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'itemmgmt_attr_value_type' => ['name' => 'itemmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'],
'itemmgmt_attr_value_valueStr' => ['name' => 'itemmgmt_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
'itemmgmt_attr_value_valueInt' => ['name' => 'itemmgmt_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'itemmgmt_attr_value_valueDec' => ['name' => 'itemmgmt_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'itemmgmt_attr_value_valueDat' => ['name' => 'itemmgmt_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'itemmgmt_attr_value_lang' => ['name' => 'itemmgmt_attr_value_lang', 'type' => 'string', 'internal' => 'language'],
'itemmgmt_attr_value_country' => ['name' => 'itemmgmt_attr_value_country', 'type' => 'string', 'internal' => 'country'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
protected static array $ownsOne = [
'language' => [
'mapper' => LanguageMapper::class,
'external' => 'itemmgmt_attr_value_lang',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
'mapper' => LanguageMapper::class,
'external' => 'itemmgmt_attr_value_lang',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
],
'country' => [
'mapper' => CountryMapper::class,
'external' => 'itemmgmt_attr_value_country',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
'mapper' => CountryMapper::class,
'external' => 'itemmgmt_attr_value_country',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
],
];

View File

@ -18,7 +18,7 @@ use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\ISO639x1Enum;
/**
* Item class.
* Localization of the item class.
*
* @package Modules\ItemManagement\Models
* @license OMS License 1.0
@ -70,7 +70,9 @@ class ItemL11n implements \JsonSerializable, ArrayableInterface
/**
* Constructor.
*
* @param string $description Title
* @param int|ItemL11nType $type Item localization type
* @param string $description Description/content
* @param string $language Language
*
* @since 1.0.0
*/
@ -136,7 +138,7 @@ class ItemL11n implements \JsonSerializable, ArrayableInterface
/**
* Get type
*
* @return int
* @return int|ItemL11nType
*
* @since 1.0.0
*/

View File

@ -36,30 +36,30 @@ final class ItemL11nMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static array $columns = [
'itemmgmt_item_l11n_id' => ['name' => 'itemmgmt_item_l11n_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_item_l11n_description' => ['name' => 'itemmgmt_item_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
'itemmgmt_item_l11n_item' => ['name' => 'itemmgmt_item_l11n_item', 'type' => 'int', 'internal' => 'item'],
'itemmgmt_item_l11n_lang' => ['name' => 'itemmgmt_item_l11n_lang', 'type' => 'string', 'internal' => 'language'],
'itemmgmt_item_l11n_typeref' => ['name' => 'itemmgmt_item_l11n_typeref', 'type' => 'int', 'internal' => 'type'],
'itemmgmt_item_l11n_id' => ['name' => 'itemmgmt_item_l11n_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_item_l11n_description' => ['name' => 'itemmgmt_item_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
'itemmgmt_item_l11n_item' => ['name' => 'itemmgmt_item_l11n_item', 'type' => 'int', 'internal' => 'item'],
'itemmgmt_item_l11n_lang' => ['name' => 'itemmgmt_item_l11n_lang', 'type' => 'string', 'internal' => 'language'],
'itemmgmt_item_l11n_typeref' => ['name' => 'itemmgmt_item_l11n_typeref', 'type' => 'int', 'internal' => 'type'],
];
/**
* Has one relation.
*
* @var array<string, array{mapper:string, self:string, by?:string, column?:string}>
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0
*/
protected static array $ownsOne = [
'language' => [
'mapper' => LanguageMapper::class,
'external' => 'itemmgmt_item_l11n_lang',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
'mapper' => LanguageMapper::class,
'external' => 'itemmgmt_item_l11n_lang',
'by' => 'code2',
'column' => 'code2',
'conditional' => true,
],
'type' => [
'mapper' => ItemL11nTypeMapper::class,
'external' => 'itemmgmt_item_l11n_typeref',
'mapper' => ItemL11nTypeMapper::class,
'external' => 'itemmgmt_item_l11n_typeref',
],
];

View File

@ -35,9 +35,9 @@ class ItemL11nType implements \JsonSerializable, ArrayableInterface
protected int $id = 0;
/**
* Item type.
* Item title.
*
* @var int
* @var string
* @since 1.0.0
*/
protected string $title = '';
@ -45,7 +45,7 @@ class ItemL11nType implements \JsonSerializable, ArrayableInterface
/**
* Constructor.
*
* @param string $description Title
* @param string $title Title
*
* @since 1.0.0
*/

View File

@ -34,9 +34,9 @@ final class ItemMapper extends DataMapperAbstract
* @since 1.0.0
*/
protected static array $columns = [
'itemmgmt_item_id' => ['name' => 'itemmgmt_item_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_item_no' => ['name' => 'itemmgmt_item_no', 'type' => 'string', 'internal' => 'number', 'autocomplete' => true],
'itemmgmt_item_info' => ['name' => 'itemmgmt_item_info', 'type' => 'string', 'internal' => 'info'],
'itemmgmt_item_id' => ['name' => 'itemmgmt_item_id', 'type' => 'int', 'internal' => 'id'],
'itemmgmt_item_no' => ['name' => 'itemmgmt_item_no', 'type' => 'string', 'internal' => 'number', 'autocomplete' => true],
'itemmgmt_item_info' => ['name' => 'itemmgmt_item_info', 'type' => 'string', 'internal' => 'info'],
];
protected static array $conditionals = [
@ -67,24 +67,24 @@ final class ItemMapper extends DataMapperAbstract
*/
protected static array $hasMany = [
'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'itemmgmt_item_media', /* table of the related object, null if no relation table is used (many->1) */
'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'itemmgmt_item_media', /* table of the related object, null if no relation table is used (many->1) */
'external' => 'itemmgmt_item_media_media',
'self' => 'itemmgmt_item_media_item',
],
'l11n' => [
'mapper' => ItemL11nMapper::class,
'table' => 'itemmgmt_item_l11n',
'self' => 'itemmgmt_item_l11n_item',
'conditional' => true,
'external' => null,
'mapper' => ItemL11nMapper::class,
'table' => 'itemmgmt_item_l11n',
'self' => 'itemmgmt_item_l11n_item',
'conditional' => true,
'external' => null,
],
'attributes' => [
'mapper' => ItemAttributeMapper::class,
'table' => 'itemmgmt_item_attr',
'self' => 'itemmgmt_item_attr_item',
'conditional' => true,
'external' => null,
'mapper' => ItemAttributeMapper::class,
'table' => 'itemmgmt_item_attr',
'self' => 'itemmgmt_item_attr_item',
'conditional' => true,
'external' => null,
],
];
}

View File