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

InformationWrapper   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 61
ccs 19
cts 21
cp 0.9048
rs 10
c 2
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addInformation() 0 7 2
A addInformationArray() 0 9 2
A __construct() 0 3 1
A addInformationWrapper() 0 7 2
A getInformations() 0 3 1
A getInformationsAsString() 0 3 1
A isEmpty() 0 3 1
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