Completed
Push — develop ( 2b7e50...d1ae17 )
by Mikaël
23:57
created

PatternRule::applyRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A PatternRule::testConditions() 0 3 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
class PatternRule extends AbstractRule
6
{
7
    /**
8
     * @return string
9
     */
10 78
    public function name()
11
    {
12 78
        return 'pattern';
13
    }
14
15
    /**
16
     * @param string $parameterName
17
     * @param mixed $value
18
     * @param bool $itemType
19
     * @return string
20
     */
21 78
    public function testConditions($parameterName, $value, $itemType = false)
22
    {
23 78
        return sprintf('is_scalar($%1$s) && !preg_match(\'/%2$s/\', $%1$s)', $parameterName, addcslashes($value, '\'\\/'));
24
    }
25
26
    /**
27
     * @param string $parameterName
28
     * @param mixed $value
29
     * @param bool $itemType
30
     * @return string
31
     */
32 78
    public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
33
    {
34 78
        return sprintf('sprintf(\'Invalid value %%s, please provide a scalar value that matches "%s"\', var_export($%s, true))', str_replace("'", "\'", $value), $parameterName);
35
    }
36
}
37