Test Failed
Push — master ( ef12af...52cb59 )
by Vincent
06:49
created

ImplodeErrorPrinter::field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bdf\Form\Error;
4
5
use Bdf\Form\Child\Http\HttpFieldPath;
6
7
/**
8
 * Implode all errors into a string
9
 * The printer will visit recursively all children
10
 */
11
final class ImplodeErrorPrinter implements FormErrorPrinterInterface
12
{
13
    /**
14
     * The errors separator
15
     *
16
     * @var string
17
     */
18
    private $separator;
19
20
    /**
21
     * Lines of errors
22
     *
23
     * @var string[]
24
     */
25
    private $lines = [];
26
27
    /**
28
     * Does the printer is visiting a child ?
29
     * If true, call to print will do nothing
30
     *
31
     * @var bool
32
     */
33
    private $inChild = false;
34
35
36
    /**
37
     * ImplodeErrorsPrinter constructor.
38
     *
39 3
     * @param string $separator
40
     */
41 3
    public function __construct(string $separator = PHP_EOL)
42 3
    {
43
        $this->separator = $separator;
44
    }
45
46
    /**
47 3
     * {@inheritdoc}
48
     */
49 3
    public function field(HttpFieldPath $field): void
50 3
    {
51
        // Ignore field name
52
    }
53
54
    /**
55 3
     * {@inheritdoc}
56
     */
57
    public function global(string $error): void
58 3
    {
59
        $this->lines[] = $error;
60
    }
61
62
    /**
63 2
     * {@inheritdoc}
64
     */
65 2
    public function code(string $code): void
66 2
    {
67 2
        // Ignore code
68 2
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 3
    public function child(string $name, FormError $error): void
74
    {
75 3
        $this->inChild = true;
76
        $error->print($this);
77
        $this->inChild = false;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function print()
84
    {
85
        return $this->inChild ? null : implode($this->separator, $this->lines);
86
    }
87
}
88