From 200f545fd53d3d3f0d67ce65795e69fd46ba742a Mon Sep 17 00:00:00 2001 From: Brandon Kelly Date: Tue, 14 Jul 2020 10:50:41 -0700 Subject: [PATCH] Cleanup --- src/models/LineItem.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/models/LineItem.php b/src/models/LineItem.php index 2474355050..45ada77597 100644 --- a/src/models/LineItem.php +++ b/src/models/LineItem.php @@ -27,6 +27,7 @@ use LitEmoji\LitEmoji; use yii\base\InvalidConfigException; use yii\behaviors\AttributeTypecastBehavior; +use yii\validators\Validator; /** * Line Item model representing a line item on an order. @@ -445,7 +446,8 @@ public function defineRules(): array $purchasable = Craft::$app->getElements()->getElementById($this->purchasableId); if ($purchasable && !empty($purchasableRules = $purchasable->getLineItemRules($this))) { foreach ($purchasableRules as $rule) { - $rules[] = $this->_normalizePurchasableRule($rule); + $this->_normalizePurchasableRule($rule); + $rules[] = $rule; } } } @@ -456,19 +458,17 @@ public function defineRules(): array /** * Normalizes a purchasable’s validation rule. * - * @param mixed $rule - * @return mixed + * @param Validator|array $rule */ - private function _normalizePurchasableRule($rule) + private function _normalizePurchasableRule(&$rule) { - if (isset($rule[1]) && $rule[1] instanceof \Closure) { + if (is_array($rule) && isset($rule[1]) && $rule[1] instanceof \Closure) { + // Wrap the closure in another one, so InlineValidator doesn’t bind it to the model $method = $rule[1]; - $rule[1] = function($attribute, $params, $validator, $current) use($method) { + $rule[1] = function($attribute, $params, $validator, $current) use ($method) { $method($attribute, $params, $validator, $current); }; } - - return $rule; } /**