PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/Framework/FieldsAPI/Concerns/InsertNode.php +23 -13 2.30.04.16.9 View file →
@@ -27,14 +27,14 @@
27 27 return $this;
28 28 }
29 29
30 30 /**
31 + * @since 4.8.0 Updated to only fall through if no node was found
31 32 * @since 2.10.2
32 33 *
33 - * @return void
34 34 * @throws ReferenceNodeNotFoundException|NameCollisionException
35 35 */
36 - protected function insertAfterRecursive(string $siblingName, Node $node)
36 + protected function insertAfterRecursive(string $siblingName, Node $node): bool
37 37 {
38 38 $siblingIndex = $this->getNodeIndexByName($siblingName);
39 39 if (null !== $siblingIndex) {
40 40 $this->insert(
@@ -41,21 +41,26 @@
41 41 $node,
42 42 $siblingIndex + 1
43 43 );
44 44
45 - return;
45 + return true;
46 46 }
47 47
48 48 if ($this->nodes) {
49 49 foreach ($this->nodes as $childNode) {
50 50 if ($childNode instanceof Collection) {
51 - $childNode->insertAfter($siblingName, $node);
51 + try {
52 + $childNode->insertAfter($siblingName, $node);
53 + return true; // Stop searching after successful insertion
54 + } catch (ReferenceNodeNotFoundException $e) {
55 + // Continue searching in other child nodes
56 + continue;
57 + }
52 58 }
53 59 }
54 -
55 - return;
56 60 }
57 61
62 + // Only throw exception if this is the root call and no node was found
58 63 throw new ReferenceNodeNotFoundException($siblingName);
59 64 }
60 65
61 66 /**
@@ -73,35 +78,40 @@
73 78 return $this;
74 79 }
75 80
76 81 /**
82 + * @since 4.8.0 Updated to only fall through if no node was found
77 83 * @since 2.10.2
78 84 *
79 - * @return void
80 85 * @throws ReferenceNodeNotFoundException|NameCollisionException
81 86 */
82 - protected function insertBeforeRecursive(string $siblingName, Node $node)
87 + protected function insertBeforeRecursive(string $siblingName, Node $node): bool
83 88 {
84 89 $siblingIndex = $this->getNodeIndexByName($siblingName);
85 90 if (null !== $siblingIndex) {
86 91 $this->insert(
87 92 $node,
88 - $siblingIndex - 1
93 + $siblingIndex
89 94 );
90 95
91 - return;
96 + return true;
92 97 }
93 98
94 99 if ($this->nodes) {
95 100 foreach ($this->nodes as $childNode) {
96 101 if ($childNode instanceof Collection) {
97 - $childNode->insertBefore($siblingName, $node);
102 + try {
103 + $childNode->insertBefore($siblingName, $node);
104 + return true; // Stop searching after successful insertion
105 + } catch (ReferenceNodeNotFoundException $e) {
106 + // Continue searching in other child nodes
107 + continue;
108 + }
98 109 }
99 110 }
100 -
101 - return;
102 111 }
103 112
113 + // Only throw exception if this is the root call and no node was found
104 114 throw new ReferenceNodeNotFoundException($siblingName);
105 115 }
106 116
107 117 /**