From 5c3d7ea9f4519424a9bfd4d46ad4d61ac98d452f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 12 Apr 2019 19:11:15 +0200 Subject: [PATCH] Throw if `IFormParentNode::appendChild()` called with multiple args See #2509 --- .../files/lib/system/form/builder/IFormParentNode.class.php | 2 ++ .../files/lib/system/form/builder/TFormParentNode.class.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/wcfsetup/install/files/lib/system/form/builder/IFormParentNode.class.php b/wcfsetup/install/files/lib/system/form/builder/IFormParentNode.class.php index 38f49220e4..5fa7070800 100644 --- a/wcfsetup/install/files/lib/system/form/builder/IFormParentNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/IFormParentNode.class.php @@ -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); diff --git a/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php b/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php index 799f6c9a82..6416eb7414 100644 --- a/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/TFormParentNode.class.php @@ -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); -- 2.20.1