Completed
Push — master ( c48d7b...aaa409 )
by Timo
04:06
created

Header::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace hamburgscleanest\DataTables\Models;
4
5
use hamburgscleanest\DataTables\Interfaces\HeaderFormatter;
6
use Illuminate\Http\Request;
7
8
/**
9
 * Class Header
10
 * @package hamburgscleanest\hamburgscleanest\DataTables\Models
11
 */
12
class Header {
13
14
    /** @var string */
15
    public $name;
16
17
    /** @var string */
18
    private $_attributeName;
19
20
    /**
21
     * Header constructor.
22
     */
23 28
    public function __construct(Column $column)
24
    {
25 28
        $this->_attributeName = $column->getName();
26 28
        if ($column->isRelation())
27
        {
28 2
            $aggregate = $column->getAggregate();
29 2
            $this->_attributeName = ($aggregate !== 'first' ? ($aggregate . '_') : '') . $column->getRelation() . '_' . $this->_attributeName;
30
        }
31
32 28
        $this->name = $this->_attributeName;
33 28
    }
34
35
    /**
36
     * Get the original attribute name.
37
     *
38
     * @return string
39
     */
40 9
    public function getAttributeName(): string
41
    {
42 9
        return $this->_attributeName;
43
    }
44
45
    /**
46
     * @param array $headerFormatters
47
     * @param Request $request
48
     */
49 27
    public function formatArray(array $headerFormatters, Request $request)
50
    {
51 27
        foreach ($headerFormatters as $formatter)
52
        {
53 8
            $this->format($formatter, $request);
54
        }
55 27
    }
56
57
    /**
58
     * @param HeaderFormatter $headerFormatter
59
     * @param Request $request
60
     */
61 8
    public function format(HeaderFormatter $headerFormatter, Request $request)
62
    {
63 8
        $headerFormatter->format($this, $request);
64
    }
65
}