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,7 +62,9 @@ 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
*/
@ -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,32 +28,88 @@ 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;

View File

@ -51,7 +51,7 @@ final class ItemAttributeValueMapper 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

@ -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

@ -46,7 +46,7 @@ final class ItemL11nMapper 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

@ -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