mirror of
https://github.com/Karaka-Management/oms-Attribute.git
synced 2026-02-01 02:18:41 +00:00
fix static analysis
This commit is contained in:
parent
7dbdceded9
commit
2b8261a7df
93
Models/AttributeHolderTrait.php
Normal file
93
Models/AttributeHolderTrait.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\Attribute\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Attribute\Models;
|
||||
|
||||
/**
|
||||
* Item class.
|
||||
*
|
||||
* @package Modules\Attribute\Models
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
trait AttributeHolderTrait
|
||||
{
|
||||
/**
|
||||
* Add attribute to item
|
||||
*
|
||||
* @param Attribute $attribute Note
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addAttribute(Attribute $attribute) : void
|
||||
{
|
||||
$this->attributes[] = $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes
|
||||
*
|
||||
* @return Attribute[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAttributes() : array
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has attribute value
|
||||
*
|
||||
* @param string $attrName Attribute name
|
||||
* @param mixed $attrValue Attribute value
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function hasAttributeValue(string $attrName, mixed $attrValue) : bool
|
||||
{
|
||||
foreach ($this->attributes as $attribute) {
|
||||
if ($attribute->type->name === $attrName && $attribute->value->getValue() === $attrValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attribute
|
||||
*
|
||||
* @param string $attrName Attribute name
|
||||
*
|
||||
* @return null|Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getAttribute(string $attrName) : ?Attribute
|
||||
{
|
||||
foreach ($this->attributes as $attribute) {
|
||||
if ($attribute->type->name === $attrName) {
|
||||
return $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -160,8 +160,8 @@ class AttributeValue implements \JsonSerializable
|
|||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param int|string|float $value Value
|
||||
* @param int $datatype Datatype
|
||||
* @param mixed $value Value
|
||||
* @param int $datatype Datatype
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user