From e1298ba5ec526a093fea1fa7df500927b7d6476e Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Wed, 3 Jun 2020 19:39:11 +0700 Subject: [PATCH] fix argument validation messages --- src/CoreFunc.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/CoreFunc.php b/src/CoreFunc.php index d5f2acc..9617178 100644 --- a/src/CoreFunc.php +++ b/src/CoreFunc.php @@ -27,17 +27,15 @@ class CoreFunc extends Func private function validateArgs(int $count) { - if ($this->minArgs >= 0 && $count < $this->minArgs) { - if ($this->minArgs == $this->maxArgs) { - throw new MadLispException(sprintf("%s requires exactly %s argument%s", $this->name, $this->minArgs, - $this->minArgs == 1 ? '' : 's')); - } else { - throw new MadLispException(sprintf("%s requires at least %s argument%s", $this->name, $this->minArgs, - $this->minArgs == 1 ? '' : 's')); - } + if ($this->minArgs == $this->maxArgs && $count != $this->minArgs) { + throw new MadLispException(sprintf("%s requires exactly %s argument%s", $this->name, $this->minArgs, + $this->minArgs == 1 ? '' : 's')); + } elseif ($count < $this->minArgs) { + throw new MadLispException(sprintf("%s requires at least %s argument%s", $this->name, $this->minArgs, + $this->minArgs == 1 ? '' : 's')); } elseif ($this->maxArgs >= 0 && $count > $this->maxArgs) { - throw new MadLispException(sprintf("%s requires at most %s argument%s", $this->name, $this->maxArgs, - $this->maxArgs == 1 ? '' : 's')); + throw new MadLispException(sprintf("%s requires at most %s argument%s", $this->name, $this->maxArgs, + $this->maxArgs == 1 ? '' : 's')); } } }