Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jul 14, 2020
1 parent 582d9d6 commit 200f545
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/models/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 200f545

Please sign in to comment.