From 2b8261a7df626c884520aa8e52a47595a8ddca8c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 9 Apr 2023 06:03:39 +0200 Subject: [PATCH] fix static analysis --- Models/AttributeHolderTrait.php | 93 +++++++++++++++++++++++++++++++++ Models/AttributeValue.php | 4 +- 2 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 Models/AttributeHolderTrait.php diff --git a/Models/AttributeHolderTrait.php b/Models/AttributeHolderTrait.php new file mode 100644 index 0000000..d7743cc --- /dev/null +++ b/Models/AttributeHolderTrait.php @@ -0,0 +1,93 @@ +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; + } +} diff --git a/Models/AttributeValue.php b/Models/AttributeValue.php index 7d452ec..600d013 100755 --- a/Models/AttributeValue.php +++ b/Models/AttributeValue.php @@ -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 *