Completed
Branch master (c40d9b)
by Timo
02:54
created

TranslateHeader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

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