Skip to content

Commit f001637

Browse files
committed
Fix several Psalm-issues
1 parent 1c2cbe4 commit f001637

12 files changed

Lines changed: 28 additions & 13 deletions

psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
>
1010
<projectFiles>
1111
<directory name="src" />
12-
<directory name="tests" />
1312

1413
<!-- Ignore certain directories -->
1514
<ignoreFiles>

src/DOMDocumentFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private function __construct()
3636

3737

3838
/**
39-
* @param string $xml
39+
* @param non-empty-string $xml
4040
*
4141
* @return \DOMDocument
4242
*/
@@ -98,6 +98,7 @@ public static function fromFile(string $file): DOMDocument
9898
}
9999

100100
Assert::notWhitespaceOnly($xml, sprintf('File "%s" does not have content', $file), RuntimeException::class);
101+
/** @psalm-var non-empty-string $xml */
101102
return static::fromString($xml);
102103
}
103104

src/ElementInterface.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ interface ElementInterface
2121
public function getQualifiedName(): string;
2222

2323

24-
/**
25-
* Test if an object, at the state it's in, would produce an empty XML-element
26-
*
27-
* @return bool
28-
*/
29-
public function isEmptyElement(): bool;
30-
31-
3224
/**
3325
* Get the value of an attribute from a given element.
3426
*

src/Exception/UnparseableXMLException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
final class UnparseableXMLException extends RuntimeException
1414
{
15-
/** @var array */
15+
/** @var string[] */
1616
private const LEVELMAP = [
1717
LIBXML_ERR_WARNING => 'WARNING',
1818
LIBXML_ERR_ERROR => 'ERROR',

src/ExtendableElementTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ trait ExtendableElementTrait
3434
/**
3535
* Set an array with all elements present.
3636
*
37-
* @param array \SimpleSAML\XML\ElementInterface[]
37+
* @param \SimpleSAML\XML\ElementInterface[] $elements
3838
* @return void
3939
*/
4040
protected function setElements(array $elements): void
@@ -59,7 +59,8 @@ protected function setElements(array $elements): void
5959
* @param \SimpleSAML\XML\ElementInterface $elt
6060
* @return string|null
6161
*/
62-
function ($elt) {
62+
function (ElementInterface $elt) {
63+
/** @psalm-var \SimpleSAML\XML\Chunk|\SimpleSAML\XML\AbstractElement $elt */
6364
return ($elt instanceof Chunk) ? $elt->getNamespaceURI() : $elt::getNamespaceURI();
6465
},
6566
$elements

src/SerializableElementInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ interface SerializableElementInterface
2121
public function __toString(): string;
2222

2323

24+
/**
25+
* Test if an object, at the state it's in, would produce an empty XML-element
26+
*
27+
* @return bool
28+
*/
29+
public function isEmptyElement(): bool;
30+
31+
2432
/**
2533
* Create a class from XML
2634
*

src/SerializableElementTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function __unserialize(array $serialized): void
8585
* @codeCoverageIgnore
8686
* @param array $data
8787
* @return static
88+
* @psalm-suppress MethodSignatureMismatch
8889
*/
8990
public static function fromArray(/** @scrutinizer ignore-unused */array $data): static
9091
{

src/Utils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public static function copyElement(DOMElement $element, DOMElement $parent = nul
6161
$parent->appendChild($newElement);
6262

6363
foreach ($namespaces as $prefix => $uri) {
64+
/** @psalm-suppress PossiblyNullArgument */
6465
$newElement->setAttributeNS($uri, $prefix . ':__ns_workaround__', 'tmp');
66+
/** @psalm-suppress PossiblyNullArgument */
6567
$newElement->removeAttributeNS($uri, '__ns_workaround__');
6668
}
6769

@@ -201,6 +203,8 @@ public static function xsDateTimeToTimestamp(string $time): int
201203
$dateTime2 = DateTimeImmutable::createFromFormat(DateTimeImmutable::RFC3339_EXTENDED, $time);
202204

203205
$dateTime = $dateTime1 ?: $dateTime2;
206+
Assert::isInstanceOf($dateTime, DateTimeImmutable::class);
207+
/** @psalm-var \DateTimeImmutable $dateTime */
204208
return $dateTime->getTimestamp();
205209
}
206210
}

tests/PHPUnit/SchemaValidationTestTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DOMDocument;
88
use libXMLError;
9+
use SimpleSAML\Assert\Assert;
910
use SimpleSAML\XML\Exception\SchemaViolationException;
1011
use XMLReader;
1112

@@ -55,14 +56,18 @@ public function testSchemaValidation(): void
5556
);
5657
} else {
5758
$predoc = XMLReader::XML($this->xmlRepresentation->saveXML());
59+
Assert::notFalse($predoc);
5860

61+
/** @psalm-var \XMLReader $predoc */
5962
$pre = $this->validateDocument($predoc);
6063
$this->assertTrue($pre);
6164

6265
$class = $this->testedClass::fromXML($this->xmlRepresentation->documentElement);
6366
$serializedClass = $class->toXML();
6467

6568
$postdoc = XMLReader::XML($serializedClass->ownerDocument->saveXML());
69+
Assert::notFalse($postdoc);
70+
/** @psalm-var \XMLReader $postdoc */
6671
$post = $this->validateDocument($postdoc);
6772
$this->assertTrue($post);
6873
}

tests/Utils/ExtendableElement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function toXML(DOMElement $parent = null): DOMElement
100100
{
101101
$e = $this->instantiateParentElement();
102102

103+
/** @psalm-var \SimpleSAML\XML\SerializableElementInterface $elt */
103104
foreach ($this->getElements() as $elt) {
104105
if (!$elt->isEmptyElement()) {
105106
$elt->toXML($e);

0 commit comments

Comments
 (0)