Passed
Branch main (b6a268)
by Iain
04:11
created

Field   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutput() 0 5 1
A isLink() 0 3 1
A getName() 0 3 1
A getViewType() 0 3 1
A isSortable() 0 3 1
A getHeaderName() 0 5 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Humbly Arrogant Ltd 2020-2022.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.0.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Athena;
16
17
use Parthenon\Athena\ViewType\ViewTypeInterface;
18
use Parthenon\Common\FieldAccesorTrait;
19
20
final class Field
21
{
22
    use FieldAccesorTrait;
23
24
    private string $name;
25
    private ViewTypeInterface $viewType;
26
    private bool $sortable;
27
    private bool $link;
28
29
    public function __construct(string $name, ViewTypeInterface $viewType, $sortable = false, bool $link = false)
30
    {
31
        $this->name = $name;
32
        $this->viewType = $viewType;
33
        $this->sortable = $sortable;
34
        $this->link = $link;
35
    }
36
37
    public function getName(): string
38
    {
39
        return $this->name;
40
    }
41
42
    public function getOutput($item)
43
    {
44
        $this->viewType->setData($this->getFieldData($item, $this->name));
45
46
        return $this->viewType->getHtmlOutput();
47
    }
48
49
    public function getViewType(): ViewTypeInterface
50
    {
51
        return $this->viewType;
52
    }
53
54
    public function isSortable(): bool
55
    {
56
        return $this->sortable;
57
    }
58
59
    public function isLink(): bool
60
    {
61
        return $this->link;
62
    }
63
64
    public function getHeaderName(): string
65
    {
66
        $headerName = str_replace('.', ' ', $this->name);
67
68
        return ucwords(str_replace('_', ' ', $headerName));
69
    }
70
}
71