Skip to content

Commit c0185b7

Browse files
Refactor
1 parent 87bbfc7 commit c0185b7

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

src/Util/Xml/Loader.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function libxml_get_errors;
1515
use function libxml_use_internal_errors;
1616
use function sprintf;
17+
use function trim;
1718
use DOMDocument;
1819

1920
/**
@@ -42,25 +43,25 @@ public function loadFile(string $filename): DOMDocument
4243
);
4344
}
4445

45-
return $this->load($contents, $filename);
46+
if (trim($contents) === '') {
47+
throw new XmlException(
48+
sprintf(
49+
'Could not parse XML from empty file "%s"',
50+
$filename,
51+
),
52+
);
53+
}
54+
55+
return $this->load($contents);
4656
}
4757

4858
/**
4959
* @throws XmlException
5060
*/
51-
public function load(string $actual, ?string $filename = null): DOMDocument
61+
public function load(string $actual): DOMDocument
5262
{
5363
if ($actual === '') {
54-
if ($filename === null) {
55-
throw new XmlException('Could not parse XML from empty string');
56-
}
57-
58-
throw new XmlException(
59-
sprintf(
60-
'Could not parse XML from empty file "%s"',
61-
$filename,
62-
),
63-
);
64+
throw new XmlException('Could not parse XML from empty string');
6465
}
6566

6667
$document = new DOMDocument;
@@ -78,17 +79,7 @@ public function load(string $actual, ?string $filename = null): DOMDocument
7879
libxml_use_internal_errors($internal);
7980
error_reporting($reporting);
8081

81-
if ($loaded === false || $message !== '') {
82-
if ($filename !== null) {
83-
throw new XmlException(
84-
sprintf(
85-
'Could not load "%s"%s',
86-
$filename,
87-
$message !== '' ? ":\n" . $message : '',
88-
),
89-
);
90-
}
91-
82+
if ($loaded === false) {
9283
if ($message === '') {
9384
$message = 'Could not load XML for unknown reason';
9485
}

0 commit comments

Comments
 (0)