Skip to content

Commit 74b26dd

Browse files
committed
Few psalm-fixes
1 parent f183e58 commit 74b26dd

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/DOMDocumentFactory.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use function libxml_get_last_error;
2121
use function libxml_use_internal_errors;
2222
use function sprintf;
23-
use function trim;
2423

2524
/**
2625
* @package simplesamlphp/xml-common
@@ -43,7 +42,7 @@ private function __construct()
4342
*/
4443
public static function fromString(string $xml): DOMDocument
4544
{
46-
Assert::stringNotEmpty(trim($xml));
45+
Assert::notWhitespaceOnly($xml);
4746

4847
$internalErrors = libxml_use_internal_errors(true);
4948
libxml_clear_errors();
@@ -98,10 +97,7 @@ public static function fromFile(string $file): DOMDocument
9897
throw new IOException("File '$file' was not loaded; $error");
9998
}
10099

101-
if (trim($xml) === '') {
102-
throw new RuntimeException(sprintf('File "%s" does not have content', $file));
103-
}
104-
100+
Assert::notWhitespaceOnly($xml, sprintf('File "%s" does not have content', $file), RuntimeException::class);
105101
return static::fromString($xml);
106102
}
107103

tests/Utils/ExtendableAttributesElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function fromXML(DOMElement $xml): static
7575
Assert::same($xml->localName, 'ExtendableAttributesElement', InvalidDOMElementException::class);
7676
Assert::same($xml->namespaceURI, 'urn:x-simplesamlphp:namespace', InvalidDOMElementException::class);
7777

78-
return new self(self::getAttributesNSFromXML($xml));
78+
return new static(self::getAttributesNSFromXML($xml));
7979
}
8080

8181

tests/src/DOMDocumentFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testFileWithValidXMLCanBeLoaded(): void
7373

7474

7575
/**
76-
* @group domdocument
76+
* @group domdocument
7777
*/
7878
public function testFileThatContainsDocTypeIsNotAccepted(): void
7979
{
@@ -87,7 +87,7 @@ public function testFileThatContainsDocTypeIsNotAccepted(): void
8787

8888

8989
/**
90-
* @group domdocument
90+
* @group domdocument
9191
*/
9292
public function testStringThatContainsDocTypeIsNotAccepted(): void
9393
{
@@ -101,7 +101,7 @@ public function testStringThatContainsDocTypeIsNotAccepted(): void
101101

102102

103103
/**
104-
* @group domdocument
104+
* @group domdocument
105105
*/
106106
public function testEmptyFileIsNotValid(): void
107107
{
@@ -119,8 +119,8 @@ public function testEmptyStringIsNotValid(): void
119119
{
120120
$this->expectException(AssertionFailedException::class);
121121
$this->expectExceptionMessage(
122-
'Expected a different value than "".',
122+
'Expected a non-whitespace string. Got: ""',
123123
);
124-
DOMDocumentFactory::fromString("");
124+
DOMDocumentFactory::fromString('');
125125
}
126126
}

0 commit comments

Comments
 (0)