EwsConfigurationRequestDetailsType   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 15

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAny() 0 8 4
B setAny() 0 9 10
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StructType;
6
7
use InvalidArgumentException;
8
use WsdlToPhp\PackageBase\AbstractStructBase;
9
10
/**
11
 * This class stands for ConfigurationRequestDetailsType StructType
12
 * @package Ews
13
 * @subpackage Structs
14
 * @author WsdlToPhp <[email protected]>
15
 */
16
class EwsConfigurationRequestDetailsType extends AbstractStructBase
17
{
18
    /**
19
     * The any
20
     * @var \DOMDocument|string|null
21
     */
22
    protected $any = null;
23
    /**
24
     * Constructor method for ConfigurationRequestDetailsType
25
     * @uses EwsConfigurationRequestDetailsType::setAny()
26
     * @param \DOMDocument|string|null $any
27
     */
28
    public function __construct($any = null)
29
    {
30
        $this
31
            ->setAny($any);
32
    }
33
    /**
34
     * Get any value
35
     * @uses \DOMDocument::loadXML()
36
     * @param bool $asString true: returns XML string, false: returns \DOMDocument
37
     * @return \DOMDocument|string|null
38
     */
39
    public function getAny(bool $asDomDocument = false)
40
    {
41
        $domDocument = null;
42
        if (!empty($this->any) && $asDomDocument) {
43
            $domDocument = new \DOMDocument('1.0', 'UTF-8');
44
            $domDocument->loadXML($this->any);
0 ignored issues
show
Bug introduced by
It seems like $this->any can also be of type DOMDocument; however, parameter $source of DOMDocument::loadXML() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $domDocument->loadXML(/** @scrutinizer ignore-type */ $this->any);
Loading history...
45
        }
46
        return $asDomDocument ? $domDocument : $this->any;
47
    }
48
    /**
49
     * Set any value
50
     * @uses \DOMDocument::hasChildNodes()
51
     * @uses \DOMDocument::saveXML()
52
     * @uses \DOMNode::item()
53
     * @param \DOMDocument|string|null $any
54
     * @return \StructType\EwsConfigurationRequestDetailsType
55
     */
56
    public function setAny($any = null): self
57
    {
58
        // validation for constraint: xml
59
        if (!is_null($any) && !$any instanceof \DOMDocument && (!is_string($any) || (is_string($any) && (empty($any) || (($anyDoc = new \DOMDocument()) && false === $anyDoc->loadXML($any)))))) {
0 ignored issues
show
introduced by
The condition is_string($any) is always true.
Loading history...
60
            throw new InvalidArgumentException(sprintf('Invalid value %s, please provide a valid XML string', var_export($any, true)), __LINE__);
61
        }
62
        $this->any = ($any instanceof \DOMDocument) ? $any->saveXML($any->hasChildNodes() ? $any->childNodes->item(0) : null) : $any;
63
        
64
        return $this;
65
    }
66
}
67