Completed
Push — master ( aaa409...98f154 )
by Timo
04:23
created

Header   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 70
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A getAttributeName() 0 4 1
A formatArray() 0 9 2
A format() 0 6 1
A print() 0 4 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
27 28
        $relation = $column->getRelation();
28 28
        if ($relation !== null)
29
        {
30 2
            $aggregate = $relation->aggregate;
31 2
            $this->_attributeName = ($aggregate !== 'first' ? ($aggregate . '_') : '') . $relation->name . '_' . $this->_attributeName;
32
        }
33
34 28
        $this->name = $this->_attributeName;
35 28
    }
36
37
    /**
38
     * Get the original attribute name.
39
     *
40
     * @return string
41
     */
42 9
    public function getAttributeName(): string
43
    {
44 9
        return $this->_attributeName;
45
    }
46
47
    /**
48
     * @param array $headerFormatters
49
     * @param Request $request
50
     * @return Header
51
     */
52 27
    public function formatArray(array $headerFormatters, Request $request): Header
53
    {
54 27
        foreach ($headerFormatters as $formatter)
55
        {
56 8
            $this->format($formatter, $request);
57
        }
58
59 27
        return $this;
60
    }
61
62
    /**
63
     * @param HeaderFormatter $headerFormatter
64
     * @param Request $request
65
     * @return Header
66
     */
67 8
    public function format(HeaderFormatter $headerFormatter, Request $request): Header
68
    {
69 8
        $headerFormatter->format($this, $request);
70
71 8
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function print(): string
78
    {
79
        return '<th>' . $this->name . '</th>';
80
    }
81
}