Throw if `IFormParentNode::appendChild()` called with multiple args
authorMatthias Schmidt <gravatronics@live.com>
Fri, 12 Apr 2019 17:11:15 +0000 (19:11 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 12 Apr 2019 17:11:15 +0000 (19:11 +0200)
See #2509

wcfsetup/install/files/lib/system/form/builder/IFormParentNode.class.php
wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php

index 38f49220e4d4f32c98d6a90fae122aaf2fbed26f..5fa70708005b9679b019eb759b3e3fc75ad964b6 100644 (file)
@@ -16,6 +16,8 @@ interface IFormParentNode extends \Countable, IFormNode, \RecursiveIterator {
         * 
         * @param       IFormChildNode          $child          appended child
         * @return      static                                  this node
+        * 
+        * @throws      \BadMethodCallException         if method is called with multiple `IFormChildNode` as parameter (if mistakenly used instead of `appendChildren()`)
         */
        public function appendChild(IFormChildNode $child);
        
index 799f6c9a82ede2b949ce31fef364f7a30dd8c739..6416eb74141204b382fc26f1db3d419ce7ebd4e1 100644 (file)
@@ -32,8 +32,14 @@ trait TFormParentNode {
         * 
         * @param       IFormChildNode          $child          appended child
         * @return      static                                  this node
+        * 
+        * @throws      \BadMethodCallException         if method is called with more than one parameter (might be mistakenly used instead of `appendChildren()`)
         */
        public function appendChild(IFormChildNode $child) {
+               if (func_num_args() > 1) {
+                       throw new \BadMethodCallException("'" . IFormParentNode::class . "::appendChild()' only supports one argument. Use '" . IFormParentNode::class . "::appendChildren()' to append multiple children at once.");
+               }
+               
                $this->children[] = $child;
                
                $child->parent($this);