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 49dff0b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 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,16 @@ 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) {
$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 49dff0b

Please sign in to comment.