ElementViewTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 1
b 0
f 0
dl 0
loc 46
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onError() 0 7 3
A error() 0 3 1
A hasError() 0 3 1
A type() 0 3 1
1
<?php
2
3
namespace Bdf\Form\View;
4
5
/**
6
 * Implements @see ElementViewInterface
7
 *
8
 * @psalm-require-implements ElementViewInterface
9
 */
10
trait ElementViewTrait
11
{
12
    /**
13
     * @var string
14
     */
15
    private $type;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $error;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 67
    public function type(): string
26
    {
27 67
        return $this->type;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 47
    public function error(): ?string
34
    {
35 47
        return $this->error;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 34
    public function hasError(): bool
42
    {
43 34
        return $this->error !== null;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 26
    public function onError($action): ?string
50
    {
51 26
        if (!$this->hasError()) {
52 15
            return null;
53
        }
54
55 11
        return is_string($action) ? $action : $action($this);
56
    }
57
}
58