<commit_before><?php

namespace hipanel\modules\domain\cart;

use hiqdev\yii2\cart\CartPositionInterface;
use hiqdev\yii2\cart\ShoppingCart;
use yii\base\Behavior;
use yz\shoppingcart\CartActionEvent;

class DomainRelatedProductsBehavior extends Behavior
{
    public function events(): array
    {
        return [
            ShoppingCart::EVENT_POSITION_PUT => 'handle',
        ];
    }

    public function handle(CartActionEvent $event): void
    {
        /** @var ShoppingCart $cart */
        $cart = $event->sender;
        /** @var CartPositionInterface $mainPosition */
        $mainPosition = $event->position;
        if ($mainPosition instanceof DomainRenewalProduct && ($relatedPositions = $mainPosition->getRelatedPositions())) {
            foreach ($relatedPositions as $position) {
                $cart->put($position->relatedPosition);
            }
        }
    }<commit_msg>refactored<commit_after><?php

namespace hipanel\modules\domain\cart;

use hiqdev\yii2\cart\CartPositionInterface;
use hiqdev\yii2\cart\ShoppingCart;
use yii\base\Behavior;
use yz\shoppingcart\CartActionEvent;

class DomainRelatedProductsBehavior extends Behavior
{
    public function events(): array
    {
        return [
            ShoppingCart::EVENT_POSITION_PUT => 'handle',
        ];
    }

    public function handle(CartActionEvent $event): void
    {
        /** @var ShoppingCart $cart */
        $cart = $event->sender;
        /** @var CartPositionInterface $mainPosition */
        $mainPosition = $event->position;
        if ($mainPosition instanceof DomainRenewalProduct && ($relatedPositions = $mainPosition->getRelatedPositions())) {
            $positions = [];
            foreach ($relatedPositions as $position) {
                $positions[] = $position->relatedPosition;
            }
            $cart->putPositions($positions);
        }
    }
{'fraction_non_alphanumeric': 0.11485042735042734, 'fraction_numerical': 0.002136752136752137, 'mean_word_length': 2.7686116700201207, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031122', 'n_tokens_mistral': 529, 'n_tokens_neox': 512, 'n_words': 99}