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

XmlRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
dl 0
loc 15
rs 10
c 1
b 0
f 1
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
    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