Passed
Push — feature/issue-124 ( 91e4aa...dde646 )
by Mikaël
09:46
created

XmlRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 15
ccs 6
cts 6
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A exceptionMessageOnTestFailure() 0 3 1
A testConditions() 0 3 2
A name() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\File\Validation;
6
7
final class XmlRule extends AbstractRule
8
{
9 4
    public function name(): string
10
    {
11 4
        return 'xml';
12
    }
13
14 4
    public function testConditions(string $parameterName, $value, bool $itemType = false): string
15
    {
16 4
        return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'!$%1$s instanceof \DOMDocument && (!is_string($%1$s) || (is_string($%1$s) && (empty($%1$s) || (($%1$sDoc = new \DOMDocument()) && false === $%1$sDoc->loadXML($%1$s)))))', $parameterName);
17
    }
18
19 4
    public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
20
    {
21 4
        return sprintf('sprintf(\'Invalid value %%s, please provide a valid XML string\', var_export($%1$s, true))', $parameterName);
22
    }
23
}
24