| Total Complexity | 7 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | class TraitModel extends InterfaceModel implements TraitModelInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var AttributeModelInterface[]|Collection $attributes Class attributes. |
||
| 23 | */ |
||
| 24 | private $attributes; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * TraitModel constructor. |
||
| 28 | */ |
||
| 29 | public function __construct() |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | public function addAttribute(AttributeModelInterface $attribute): void |
||
| 39 | { |
||
| 40 | $this->attributes->add($attribute); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | public function hasAttribute(string $name): bool |
||
| 47 | { |
||
| 48 | return $this->attributes->exists(function (AttributeModelInterface $attribute) use ($name) { |
||
| 49 | return $attribute->getName() === $name; |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function getAttribute(string $name): ?AttributeModelInterface |
||
| 57 | { |
||
| 58 | foreach ($this->attributes as $attribute) { |
||
| 59 | if ($attribute->getName() === $name) { |
||
| 60 | return $attribute; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * {@inheritdoc} |
||
| 68 | */ |
||
| 69 | public function getAttributes(): Collection |
||
| 72 | } |
||
| 73 | } |
||
| 74 |