Skip to content

Commit de188bf

Browse files
committed
Se agrega xpath expression al XmlQueryException.
1 parent 711635c commit de188bf

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/Exception/XmlQueryException.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace Derafu\Xml\Exception;
1414

15+
use Derafu\Xml\Contract\XmlDocumentInterface;
16+
use Throwable;
17+
1518
/**
1619
* Exception thrown when an XPath query fails.
1720
*
@@ -22,4 +25,37 @@
2225
*/
2326
class XmlQueryException extends XmlException
2427
{
28+
/**
29+
* Constructor of the exception.
30+
*
31+
* @param string $message The exception message.
32+
* @param array $errors The array with the errors.
33+
* @param int $code The exception code (optional).
34+
* @param Throwable|null $previous The previous exception (optional).
35+
* @param XmlDocumentInterface|null $xmlDocument The XML document that
36+
* caused the exception or `null` if it is not present.
37+
* @param string|null $xpathExpression The XPath expression that caused the
38+
* exception or `null` if it is not present.
39+
*/
40+
public function __construct(
41+
string $message,
42+
array $errors = [],
43+
int $code = 0,
44+
?Throwable $previous = null,
45+
?XmlDocumentInterface $xmlDocument = null,
46+
private ?string $xpathExpression = null,
47+
) {
48+
parent::__construct($message, $errors, $code, $previous, $xmlDocument);
49+
}
50+
51+
/**
52+
* Gets the XPath expression that caused the exception.
53+
*
54+
* @return string|null The XPath expression that caused the exception or
55+
* `null` if it is not present.
56+
*/
57+
public function getXpathExpression(): ?string
58+
{
59+
return $this->xpathExpression;
60+
}
2561
}

tests/src/XmlTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Derafu\TestsXml;
1414

1515
use Derafu\Xml\Exception\XmlException;
16+
use Derafu\Xml\Exception\XmlQueryException;
1617
use Derafu\Xml\Service\XmlDecoder;
1718
use Derafu\Xml\XmlDocument;
1819
use Derafu\Xml\XmlHelper;
@@ -25,6 +26,7 @@
2526
#[CoversClass(XmlException::class)]
2627
#[CoversClass(XmlHelper::class)]
2728
#[CoversClass(XPathQuery::class)]
29+
#[CoversClass(XmlQueryException::class)]
2830
class XmlTest extends TestCase
2931
{
3032
/**

0 commit comments

Comments
 (0)