Skip to content

Commit

Permalink
issue WsdlToPhp#214 - fix multiple values for validation rule generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelcom committed Jan 24, 2021
1 parent 6893c72 commit 312d358
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/File/Validation/AbstractBoundRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ final public function testConditions($parameterName, $value, $itemType = false)
*/
final public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
{
return sprintf('sprintf(\'Invalid value %%s, the value must be %s %s %s\', var_export($%4$s, true))', is_numeric($value) ? 'numerically' : 'chronologically', $this->comparisonString(), $value, $parameterName);
return sprintf('sprintf(\'Invalid value %%s, the value must be %s %s %s\', var_export($%4$s, true))', is_numeric($value) ? 'numerically' : 'chronologically', $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName);
}
}
2 changes: 1 addition & 1 deletion src/File/Validation/AbstractLengthRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final public function testConditions($parameterName, $value, $itemType = false)
final public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
{
if ($itemType || !$this->getAttribute()->isArray()) {
$message = sprintf('sprintf(\'Invalid length of %%s, the number of characters/octets contained by the literal must be %s %s\', mb_strlen($%s))', $this->comparisonString(), $value, $parameterName);
$message = sprintf('sprintf(\'Invalid length of %%s, the number of characters/octets contained by the literal must be %s %s\', mb_strlen($%s))', $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName);
} else {
$message = $this->getErrorMessageVariableName($parameterName);
}
Expand Down
5 changes: 3 additions & 2 deletions src/File/Validation/MaxOccursRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function symbol()
}

/**
* If maxOccurs is 'unbounded', no need to check occurrences count
* @param string $parameterName
* @param mixed $value
* @param bool $itemType
Expand All @@ -55,7 +56,7 @@ public function symbol()
final public function testConditions($parameterName, $value, $itemType = false)
{
$test = '';
if ('unbounded' !== $value && $this->getAttribute()->isArray()) {
if ($this->getAttribute()->isArray() && ((is_scalar($value) && 'unbounded' !== $value) || (is_array($value) && !in_array('unbounded', $value)))) {
if ($itemType) {
$test = 'is_array($this->%1$s) && count($this->%1$s) %3$s %2$d';
$symbol = self::SYMBOL_MAX_EXCLUSIVE;
Expand All @@ -81,6 +82,6 @@ final public function exceptionMessageOnTestFailure($parameterName, $value, $ite
} else {
$message = 'sprintf(\'Invalid count of %%s, the number of elements contained by the property must be %1$s %2$s\', count($%3$s))';
}
return sprintf($message, $this->comparisonString(), $value, $parameterName, $this->getAttribute()->getCleanName());
return sprintf($message, $this->comparisonString(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName, $this->getAttribute()->getCleanName());
}
}

0 comments on commit 312d358

Please sign in to comment.