Passed
Push — master ( c6f342...c3162b )
by Tim
01:57
created

KeySize::getKeySize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * Class representing a xenc:KeySize element.
13
 *
14
 * @package simplesaml/xml-security
15
 * @psalm-suppress PropertyNotSetInConstructor $content
16
 */
17
final class KeySize extends AbstractXencElement
18
{
19
    /** @var int */
20
    protected int $keySize;
21
22
23
    /**
24
     * @param int $keySize
25
     */
26
    public function __construct(int $keySize)
27
    {
28
        $this->setKeySize($keySize);
29
    }
30
31
32
    /**
33
     * @param int $keySize
34
     */
35
    protected function setKeySize(int $keySize): void
36
    {
37
        Assert::positiveInteger($keySize, SchemaViolationException::class);
38
        $this->keySize = $keySize;
39
    }
40
41
42
    /**
43
     * @return int
44
     */
45
    public function getKeySize(): int
46
    {
47
        return $this->keySize;
48
    }
49
50
51
    /**
52
     * Convert XML into a class instance
53
     *
54
     * @param \DOMElement $xml The XML element we should load
55
     * @return static
56
     *
57
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
58
     *   If the qualified name of the supplied element is wrong
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\X...alidDOMElementException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64
        Assert::numeric($xml->textContent);
65
66
        return new static(intval($xml->textContent));
67
    }
68
69
70
    /**
71
     * Convert this element to XML.
72
     *
73
     * @param \DOMElement|null $parent The element we should append this element to.
74
     * @return \DOMElement
75
     */
76
    public function toXML(DOMElement $parent = null): DOMElement
77
    {
78
        $e = $this->instantiateParentElement($parent);
79
        $e->textContent = strval($this->getKeySize());
80
81
        return $e;
82
    }
83
}
84