TranslateHeader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A format() 0 7 2
1
<?php
2
3
namespace hamburgscleanest\DataTables\Models\HeaderFormatters;
4
5
use hamburgscleanest\DataTables\Interfaces\HeaderFormatter;
6
use hamburgscleanest\DataTables\Models\Header;
7
8
/**
9
 * Class TranslateHeader
10
 *
11
 * @package hamburgscleanest\DataTables\Models\HeaderFormatters
12
 */
13
class TranslateHeader implements HeaderFormatter {
14
15
    /** @var array */
16
    private $_translations;
17
18
    /**
19
     * TranslatableHeader constructor.
20
     * @param array $translations
21
     */
22 1
    public function __construct(array $translations)
23
    {
24 1
        $this->_translations = $translations;
25 1
    }
26
27
    /**
28
     * Format the given header.
29
     * For example add a link to sort by this header/column.
30
     *
31
     * @param Header $header
32
     */
33 1
    public function format(Header $header) : void
34
    {
35 1
        $headerAttributeName = $header->getAttributeName();
36
37 1
        if (isset($this->_translations[$headerAttributeName]))
38
        {
39 1
            $header->key = $this->_translations[$headerAttributeName];
40
        }
41
    }
42
}