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

TotalDigitsRule::applyRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
crap 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
class TotalDigitsRule 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 TotalDigitsRule
13
     */
14 8
    public function applyRule($parameterName, $value, $itemType = false)
15
    {
16 6
        $this
17 8
            ->getMethod()
18 8
                ->addChild('// validation for constraint: totalDigits')
19 8
                ->addChild(sprintf('if (is_float($%1$s) && strlen(str_replace(array(\' \', \'.\', \',\', \'-\', \'+\'), \'\', $%1$s)) !== %2$d) {', $parameterName, $value))
20 8
                    ->addChild($this->getMethod()->getIndentedString(sprintf('throw new \InvalidArgumentException(sprintf(\'Invalid value, the value must at most contain %1$d digits, "%%d" given\', strlen(substr($%2$s, strpos($%2$s, \'.\')))), __LINE__);', $value, $parameterName), 1))
21 8
                ->addChild('}');
22 8
        return $this;
23
    }
24
}
25