ElementViewTrait::hasError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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