Completed
Push — master ( f15fe2...9a8393 )
by Pavel
07:23 queued 11s
created

Configuration::setNoDataMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace Pfilsx\DataGrid\Config;
5
6
/**
7
 * Class DataGridConfiguration
8
 * @package Pfilsx\DataGrid\Config
9
 * @internal
10
 */
11
class Configuration implements ConfigurationInterface
12
{
13
    protected $template;
14
15
    protected $noDataMessage;
16
17
    protected $paginationLimit;
18
19
    protected $paginationEnabled;
20
21
    protected $showTitles;
22
23
    protected $translationDomain;
24
25
    public function __construct(array $config = [])
26
    {
27
        foreach ($config as $key => $value) {
28
            $key = str_replace('_', '', $key);
29
            $setter = 'set' . $key;
30
            if (method_exists($this, $setter)) {
31
                $this->$setter($value);
32
            }
33
        }
34
    }
35
36
    public function getTemplate(): ?string
37
    {
38
        return $this->template;
39
    }
40
41
    public function setTemplate(string $template): void
42
    {
43
        $this->template = $template;
44
    }
45
46
    public function getNoDataMessage(): ?string
47
    {
48
        return $this->noDataMessage;
49
    }
50
51
    public function setNoDataMessage(string $message): void
52
    {
53
        $this->noDataMessage = $message;
54
    }
55
56
    public function setPaginationEnabled(bool $value): void
57
    {
58
        $this->paginationEnabled = $value;
59
    }
60
61
    public function setPaginationLimit(int $limit): void
62
    {
63
        $this->paginationLimit = $limit;
64
    }
65
66
67
    public function setTranslationDomain(?string $domain): void
68
    {
69
        $this->translationDomain = $domain;
70
    }
71
72
    public function getConfigsArray(): array
73
    {
74
        return [
75
            'template' => $this->getTemplate(),
76
            'paginationEnabled' => $this->getPaginationEnabled(),
77
            'paginationLimit' => $this->getPaginationLimit(),
78
            'noDataMessage' => $this->getNoDataMessage(),
79
            'translationDomain' => $this->getTranslationDomain()
80
        ];
81
    }
82
83
    public function merge(ConfigurationInterface $configuration): ConfigurationInterface
84
    {
85
        $result = clone $this;
86
        foreach ($configuration->getConfigsArray() as $key => $value) {
87
            if ($value !== null) {
88
                $setter = 'set' . ucfirst($key);
89
                $result->$setter($value);
90
            }
91
        }
92
        return $result;
93
    }
94
95
    public function getPaginationLimit(): ?int
96
    {
97
        return $this->paginationLimit;
98
    }
99
100
    public function getPaginationEnabled(): ?bool
101
    {
102
        return $this->paginationEnabled;
103
    }
104
105
    public function getTranslationDomain(): ?string
106
    {
107
        return $this->translationDomain;
108
    }
109
}
110