Passed
Push — master ( ddb420...13a60b )
by Dispositif
02:30
created

InfoTrait::setInfo()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application
4
 * 2019 © Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the LICENSE file.
6
 */
7
8
declare(strict_types=1);
9
10
11
namespace App\Domain\Models\Wiki;
12
13
/**
14
 * Allows storage of hidden information or storage of parameter values
15
 * not serialized in a wiki-template.
16
 * Trait InfoTrait
17
 */
18
trait InfoTrait
19
{
20
    protected $infos = [];
21
22
    /**
23
     * @return array
24
     */
25
    public function getInfos(): array
26
    {
27
        return $this->infos;
28
    }
29
30
    /**
31
     * @param array $infos
32
     */
33
    public function setInfos(array $infos): void
34
    {
35
        $this->infos = $infos;
36
    }
37
38
    /**
39
     * @param string $name
40
     *
41
     * @return string|null
42
     */
43
    public function getInfo(string $name): ?string
44
    {
45
        return ($this->infos[$name]) ?? null;
46
    }
47
48
    /**
49
     * @param string $name
50
     * @param string $value
51
     */
52
    public function setInfo(string $name, string $value): void
53
    {
54
        $value = trim($value);
55
        if (!empty($value) || $this->infos[$name]) {
56
            $this->infos[$name] = $value;
57
        }
58
    }
59
}
60