MetadataTrait::getMetadatas()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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