AbstractHeader::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid\Column\Header;
8
9
use Nnx\DataGrid\Column\Header\Exception\NoValidTemplateException;
10
use Traversable;
11
12
/**
13
 * Class AbstractHeader
14
 * @package Nnx\DataGrid\Column\Header
15
 */
16
abstract class AbstractHeader implements HeaderInterface
17
{
18
    /**
19
     * Путь до шаблона
20
     * @var string
21
     */
22
    protected $template;
23
24
    /**
25
     * Опции заголовка
26
     * @var array | Traversable
27
     */
28
    protected $options;
29
30
    /**
31
     * Данные для
32
     * @var array | \Traversable
33
     */
34
    protected $data;
35
36
    /**
37
     * Заголовок
38
     * @var string
39
     */
40
    protected $title;
41
42
    /**
43
     * @param string $title
44
     * @param string $template
45
     * @param array | Traversable $data
46
     * @param array | Traversable $options
47
     * @throws NoValidTemplateException
48
     */
49
    public function __construct($title = '', $template = '', array $data = [], array $options = [])
50
    {
51
        if ($template && !is_string($template)) {
52
            throw new NoValidTemplateException(
53
                sprintf('Невалидный путь до шаблона заголовка.')
54
            );
55
        }
56
        if ($template) {
57
            $this->setTemplate($template);
58
        }
59
        if ($title) {
60
            $this->setTitle($title);
61
        }
62
        $this->setData($data);
63
        $this->setOptions($options);
64
    }
65
66
    /**
67
     * Устанавливает шаблон для заголовка табоицы
68
     * @param $template
69
     * @return $this
70
     */
71
    public function setTemplate($template)
72
    {
73
        $this->template = $template;
74
        return $this;
75
    }
76
77
    /**
78
     * возвращает путь до шаблона
79
     * @return string
80
     */
81
    public function getTemplate()
82
    {
83
        return $this->template;
84
    }
85
86
    /**
87
     * Усанавливает опции для заголовка
88
     * @param array|Traversable $options
89
     * @return mixed
90
     */
91
    public function setOptions(array $options = [])
92
    {
93
        $this->options = $options;
94
        return $this;
95
    }
96
97
    /**
98
     * Возвращает набор опций для заголовка
99
     * @return array
100
     */
101
    public function getOptions()
102
    {
103
        return $this->options;
104
    }
105
106
    /**
107
     * Данные для шаблона заголовка
108
     * @param array | \Traversable $data
109
     * @return $this
110
     */
111
    public function setData($data)
112
    {
113
        $this->data = $data;
114
        return $this;
115
    }
116
117
    /**
118
     * Возвращает данные для шаблона
119
     * @return array
120
     */
121
    public function getData()
122
    {
123
        return $this->data;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getTitle()
130
    {
131
        return $this->title;
132
    }
133
134
    /**
135
     * @param string $title
136
     * @return $this
137
     */
138
    public function setTitle($title)
139
    {
140
        $this->title = $title;
141
        return $this;
142
    }
143
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
144