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

AbstractLengthRule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exceptionMessageOnTestFailure() 0 3 1
A testConditions() 0 3 1
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