MetadataTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 35
ccs 0
cts 10
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadatas() 0 3 1
A getMetadata() 0 8 3
A appendMetadata() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Formularium;
4
5
use Formularium\Exception\Exception;
6
use Formularium\Factory\DatatypeFactory;
7
8
trait MetadataTrait
9
{
10
    /**
11
     * @var Metadata[]
12
     */
13
    protected $metadata;
14
15
    /**
16
     * All metadata objects. Yeah, that's a horrible plural, I know.
17
     *
18
     * @return Metadata[]
19
     */
20
    public function getMetadatas(): array
21
    {
22
        return $this->metadata;
23
    }
24
25
    /**
26
     * @param string $name
27
     * @return Metadata
28
     */
29
    public function getMetadata(string $name)
30
    {
31
        foreach ($this->metadata as $m) {
32
            if ($m->getName() === $name) {
33
                return $m;
34
            }
35
        }
36
        return null;
37
    }
38
39
    public function appendMetadata(Metadata $m): self
40
    {
41
        $this->metadata[] = $m;
42
        return $this;
43
    }
44
}
45