MetadataTrait::getMetadata()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 12
rs 10
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