1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PackageGenerator\File\Validation; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Gathers [min|max|]Length rules. |
9
|
|
|
*/ |
10
|
|
|
abstract class AbstractLengthRule extends AbstractMinMaxRule |
11
|
|
|
{ |
12
|
20 |
|
final public function testConditions(string $parameterName, $value, bool $itemType = false): string |
13
|
|
|
{ |
14
|
20 |
|
if ($itemType || !$this->getAttribute()->isArray()) { |
15
|
20 |
|
$test = sprintf( |
16
|
20 |
|
($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen((string) $%1$s) %3$s %2$d', |
17
|
20 |
|
$parameterName, |
18
|
20 |
|
$value, |
19
|
20 |
|
$this->symbol() |
20
|
20 |
|
); |
21
|
|
|
} else { |
22
|
6 |
|
$this->addArrayValidationMethod($parameterName, $value); |
23
|
6 |
|
$test = sprintf( |
24
|
6 |
|
'\'\' !== (%s = self::%s($%s))', |
25
|
6 |
|
$this->getArrayErrorMessageVariableName($parameterName), |
26
|
6 |
|
$this->getValidationMethodName($parameterName), |
27
|
6 |
|
$parameterName |
28
|
6 |
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
20 |
|
return $test; |
32
|
|
|
} |
33
|
|
|
|
34
|
20 |
|
final public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string |
35
|
|
|
{ |
36
|
20 |
|
if ($itemType || !$this->getAttribute()->isArray()) { |
37
|
20 |
|
$message = sprintf( |
38
|
20 |
|
'sprintf(\'Invalid length of %%s, the number of characters/octets contained by the literal must be %s %s\', mb_strlen((string) $%s))', |
39
|
20 |
|
$this->comparisonString(), |
40
|
20 |
|
is_array($value) ? implode(',', array_unique($value)) : $value, |
41
|
20 |
|
$parameterName |
42
|
20 |
|
); |
43
|
|
|
} else { |
44
|
6 |
|
$message = $this->getArrayErrorMessageVariableName($parameterName); |
45
|
|
|
} |
46
|
|
|
|
47
|
20 |
|
return $message; |
48
|
|
|
} |
49
|
|
|
|
50
|
6 |
|
final protected function getArrayExceptionMessageOnTestFailure($value): string |
51
|
|
|
{ |
52
|
6 |
|
return sprintf( |
53
|
6 |
|
'Invalid length for value(s) %%s, the number of characters/octets contained by the literal must be %s %s', |
54
|
6 |
|
$this->comparisonString(), |
55
|
6 |
|
$value |
56
|
6 |
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|