Passed
Push — feature/issue-168 ( a16e5d...f01c3b )
by Mikaël
06:47
created

AbstractLengthRule::testConditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace WsdlToPhp\PackageGenerator\File\Validation;
5
6
/**
7
 * Class AbstractLengthRule
8
 * Gathers [min|max|]Length rules
9
 * @package WsdlToPhp\PackageGenerator\File\Validation
10
 */
11
abstract class AbstractLengthRule extends AbstractMinMaxRule
12
{
13
14
    /**
15
     * @param string $parameterName
16
     * @param mixed $value
17
     * @param bool $itemType
18
     * @return string
19
     */
20
    final public function testConditions($parameterName, $value, $itemType = false)
21
    {
22
        return sprintf('(is_scalar($%1$s) && strlen($%1$s) %3$s %2$d) || (is_array($%1$s) && count($%1$s) %3$s %2$d)', $parameterName, $value, static::symbol());
23
    }
24
25
    /**
26
     * @param string $parameterName
27
     * @param mixed $value
28
     * @param bool $itemType
29
     * @return string
30
     */
31
    final public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
32
    {
33
        return sprintf('sprintf(\'Invalid length of %%s, the number of characters/octets contained by the literal or the number of elements contained by the list must be %s %s\', var_export($%3$s, true), is_scalar($%3$s) ? strlen($%3$s) : count($%3$s))', static::comparisonString(), $value, $parameterName);
34
    }
35
}
36