Passed
Push — develop ( 393819...8447c9 )
by Mikaël
74:52 queued 24:50
created

XmlRule::testConditions()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 1
b 0
f 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
    public function name(): string
10
    {
11
        return 'xml';
12
    }
13
14
    public function testConditions(string $parameterName, $value, bool $itemType = false): string
15
    {
16
        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
    public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
20
    {
21
        return sprintf('sprintf(\'Invalid value %%s, please provide a valid XML string\', var_export($%1$s, true))', $parameterName);
22
    }
23
}
24