1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: delboy1978uk |
4
|
|
|
* Date: 04/12/2016 |
5
|
|
|
* Time: 23:36 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Del\Form\Renderer\Field\Error; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use Del\Form\Field\FieldInterface; |
12
|
|
|
use DOMElement; |
13
|
|
|
use DOMText; |
14
|
|
|
|
15
|
|
|
class DefaultErrorRender extends AbstractErrorRender implements ErrorRendererInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param DOMElement $div |
|
|
|
|
19
|
|
|
* @param FieldInterface $field |
20
|
|
|
* @return DOMElement |
21
|
|
|
*/ |
22
|
2 |
|
public function render(FieldInterface $field) |
23
|
|
|
{ |
24
|
2 |
|
$helpBlock = $this->dom->createElement('span'); |
25
|
2 |
|
$helpBlock->setAttribute('class', 'help-block'); |
26
|
|
|
|
27
|
2 |
|
if ($field->hasCustomErrorMessage()) { |
28
|
1 |
|
$helpBlock = $this->addCustomErrorMessage($helpBlock, $field); |
29
|
|
|
} else { |
30
|
1 |
|
$helpBlock = $this->addErrorMessages($helpBlock, $field); |
31
|
|
|
} |
32
|
2 |
|
return $helpBlock; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param DOMElement $helpBlock |
37
|
|
|
* @param FieldInterface $field |
38
|
|
|
* @return DOMElement |
39
|
|
|
*/ |
40
|
1 |
|
private function addCustomErrorMessage(DOMElement $helpBlock, FieldInterface $field) |
41
|
|
|
{ |
42
|
1 |
|
$message = $field->getCustomErrorMessage(); |
43
|
1 |
|
$text = new DOMText($message); |
44
|
1 |
|
$helpBlock->appendChild($text); |
45
|
1 |
|
return $helpBlock; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param DOMElement $helpBlock |
50
|
|
|
* @param FieldInterface $field |
51
|
|
|
* @return DOMElement] |
|
|
|
|
52
|
|
|
*/ |
53
|
1 |
|
private function addErrorMessages(DOMElement $helpBlock, FieldInterface $field) |
54
|
|
|
{ |
55
|
1 |
|
$messages = $field->getMessages(); |
56
|
|
|
|
57
|
1 |
|
foreach ($messages as $message) { |
58
|
1 |
|
$helpBlock = $this->appendMessage($helpBlock, $message); |
59
|
|
|
} |
60
|
1 |
|
return $helpBlock; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param DOMElement $helpBlock |
65
|
|
|
* @param $message |
66
|
|
|
* @return DOMElement |
67
|
|
|
*/ |
68
|
1 |
|
private function appendMessage(DOMElement $helpBlock, $message) |
69
|
|
|
{ |
70
|
1 |
|
$text = new DOMText($message); |
71
|
1 |
|
$br = $this->dom->createElement('br'); |
72
|
1 |
|
$helpBlock->appendChild($text); |
73
|
1 |
|
$helpBlock->appendChild($br); |
74
|
1 |
|
return $helpBlock; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.