Completed
Push — master ( 1bff5d...2a2446 )
by Mikaël
75:38 queued 45:53
created

PatternRule   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 1
c 3
b 1
f 2
lcom 0
cbo 3
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A applyRule() 0 10 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
class PatternRule extends AbstractRule
6
{
7
    /**
8
     * @see \WsdlToPhp\PackageGenerator\File\Validation\AbstractValidation::addRule()
9
     * @param string $parameterName
10
     * @param mixed $value
11
     * @param bool $itemType
12
     * @return PatternRule
13
     */
14 4
    public function applyRule($parameterName, $value, $itemType = false)
15
    {
16 3
        $this
17 4
            ->getMethod()
18 4
                ->addChild('// validation for constraint: pattern')
19 4
                ->addChild(sprintf('if (is_scalar($%1$s) && !preg_match(\'/%2$s/\', $%1$s)) {', $parameterName, $value))
20 4
                    ->addChild($this->getMethod()->getIndentedString(sprintf('throw new \InvalidArgumentException(sprintf(\'Invalid value, please provide a scalar value that matches "%s", "%%s" given\', var_export($%s, true)), __LINE__);', str_replace("'", "\'", $value), $parameterName), 1))
21 4
                ->addChild('}');
22 4
        return $this;
23
    }
24
}
25