From 0dd368cb7448d111197d3b9730f5ca495d43ba4c Mon Sep 17 00:00:00 2001 From: Jon Waldstein Date: Fri, 4 Aug 2023 12:45:39 -0400 Subject: [PATCH] feature: add existing and incoming nodes to exception --- .../FieldsAPI/Concerns/NameCollision.php | 5 +-- .../Exceptions/NameCollisionException.php | 36 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Framework/FieldsAPI/Concerns/NameCollision.php b/src/Framework/FieldsAPI/Concerns/NameCollision.php index dccb7bf66d..2fba1d7caa 100644 --- a/src/Framework/FieldsAPI/Concerns/NameCollision.php +++ b/src/Framework/FieldsAPI/Concerns/NameCollision.php @@ -26,14 +26,15 @@ public function checkNameCollisionDeep(Node $node) } /** + * @unreleased add existing and incoming nodes to exception * @since 2.10.2 * * @throws NameCollisionException */ public function checkNameCollision(Node $node) { - if ($this->getNodeByName($node->getName())) { - throw new NameCollisionException($node->getName()); + if ($existingNode = $this->getNodeByName($node->getName())) { + throw new NameCollisionException($node->getName(), $existingNode, $node); } } } diff --git a/src/Framework/FieldsAPI/Exceptions/NameCollisionException.php b/src/Framework/FieldsAPI/Exceptions/NameCollisionException.php index 63fea9bf58..579b60608d 100644 --- a/src/Framework/FieldsAPI/Exceptions/NameCollisionException.php +++ b/src/Framework/FieldsAPI/Exceptions/NameCollisionException.php @@ -3,8 +3,10 @@ namespace Give\Framework\FieldsAPI\Exceptions; use Give\Framework\Exceptions\Primitives\Exception; +use Give\Framework\FieldsAPI\Contracts\Node; /** + * @unreleased add existing and incoming nodes to exception * @since 2.10.2 */ class NameCollisionException extends Exception @@ -13,10 +15,26 @@ class NameCollisionException extends Exception * @var string */ protected $nodeNameCollision; + /** + * @var Node + */ + protected $existingNode; + /** + * @var Node + */ + protected $incomingNode; - public function __construct($name, $code = 0, Exception $previous = null) + public function __construct( + string $name, + Node $existingNode, + Node $incomingNode, + int $code = 0, + Exception $previous = null + ) { $this->nodeNameCollision = $name; + $this->existingNode = $existingNode; + $this->incomingNode = $incomingNode; $message = "Node name collision for $name"; parent::__construct($message, $code, $previous); @@ -29,4 +47,20 @@ public function getNodeNameCollision(): string { return $this->nodeNameCollision; } + + /** + * @unreleased + */ + public function getIncomingNode(): Node + { + return $this->incomingNode; + } + + /** + * @unreleased + */ + public function getExistingNode(): Node + { + return $this->existingNode; + } }