Passed
Push — master ( f4068b...77f637 )
by Nico
40:27 queued 14:09
created

InformationWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib;
6
7
class InformationWrapper
8
{
9
    /** @var array<string> */
10
    private array $informations;
11
12
    /**
13
     * @param array<string> $informations
14
     */
15 28
    public function __construct(array $informations = [])
16
    {
17 28
        $this->informations = $informations;
18
    }
19
20 13
    public function addInformation(?string $information): InformationWrapper
21
    {
22 13
        if ($information !== null) {
23 13
            $this->informations[] = $information;
24
        }
25
26 13
        return $this;
27
    }
28
29
    /**
30
     * @param array<string> $informations
31
     */
32 7
    public function addInformationArray(array $informations, bool $isHead = false): InformationWrapper
33
    {
34 7
        if ($isHead) {
35 1
            $this->informations = array_merge($informations, $this->informations);
36
        } else {
37 7
            $this->informations = array_merge($this->informations, $informations);
38
        }
39
40 7
        return $this;
41
    }
42
43 2
    public function addInformationWrapper(?InformationWrapper $informations, bool $isHead = false): InformationWrapper
44
    {
45 2
        if ($informations !== null) {
46 2
            $this->addInformationArray($informations->getInformations(), $isHead);
47
        }
48
49 2
        return $this;
50
    }
51
52
    /**
53
     * @return array<string>
54
     */
55 25
    public function getInformations(): array
56
    {
57 25
        return $this->informations;
58
    }
59
60
    public function getInformationsAsString(): string
61
    {
62
        return implode(PHP_EOL, $this->getInformations());
63
    }
64
65 2
    public function isEmpty(): bool
66
    {
67 2
        return empty($this->getInformations());
68
    }
69
}
70