<commit_before><?php
/**
 * (c) Vespolina Project http://www.vespolina-project.org
 *
 * (c) <NAME> <<EMAIL>>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Vespolina\CartBundle\Model;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use Vespolina\CartBundle\Model\CartableItemInterface;
use Vespolina\CartBundle\Model\CartInterface;
use Vespolina\CartBundle\Model\CartItemInterface;
use Vespolina\CartBundle\Model\CartManagerInterface;

abstract class CartManager implements CartManagerInterface
{
    protected $cartClass;
    protected $cartItemClass;

    function __construct($cartClass, $cartItemClass)
    {
        $this->cartClass = $cartClass;
        $this->cartItemClass = $cartItemClass;
    }

    /**
     * @inheritdoc
     */
    public function createCart($cartType = 'default')
    {
        $cart = new $this->cartClass($cartType);
        $this->initCart($cart);

        return $cart;
    }

    /**
     * @inheritdoc
     */
    public function createItem(CartableItemInterface $cartableItem = null)
    {
        $cartItem = new $this->cartItemClass($cartableItem);
        $this->initCartItem($cartItem);

        return $cartItem;
    }

    public function initCart(CartInterface $cart)
    {
        //Set default state (for now we set it to "open")
        $cart->setState(Cart::STATE_OPEN);
    }

    public function initCartItem(CartItemInterface $cartItem)
    {
        //Default cart item description to the product name
        if ($cartableItem = $cartItem->getCartableItem()) {

            $cartItem->setName($cartableItem->getName());
        }
    }

}<commit_msg>set RecurringInterface products as recurring<commit_after><?php
/**
 * (c) 2011-2012 Vespolina Project http://www.vespolina-project.org
 *
 * (c) <NAME> <<EMAIL>>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Vespolina\CartBundle\Model;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Bundle\Bundle;

use Vespolina\CartBundle\Model\CartableItemInterface;
use Vespolina\CartBundle\Model\CartInterface;
use Vespolina\CartBundle\Model\CartItemInterface;
use Vespolina\CartBundle\Model\CartManagerInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
abstract class CartManager implements CartManagerInterface
{
    protected $cartClass;
    protected $cartItemClass;
    protected $recurringInterface;

    function __construct($cartClass, $cartItemClass, $recurringInterface = 'Vespolina\ProductBundle\Model\RecurringInterface')
    {
        $this->cartClass = $cartClass;
        $this->cartItemClass = $cartItemClass;
        $this->recurringInterface = $recurringInterface;
    }

    /**
     * @inheritdoc
     */
    public function createCart($cartType = 'default')
    {
        $cart = new $this->cartClass($cartType);
        $this->initCart($cart);

        return $cart;
    }

    /**
     * @inheritdoc
     */
    public function createItem(CartableItemInterface $cartableItem = null)
    {
        $cartItem = new $this->cartItemClass($cartableItem);
        $this->initCartItem($cartItem);

        return $cartItem;
    }

    public function initCart(CartInterface $cart)
    {
        //Set default state (for now we set it to "open")
        $cart->setState(Cart::STATE_OPEN);
    }

    public function initCartItem(CartItemInterface $cartItem)
    {
        //Default cart item description to the product name
        if ($cartableItem = $cartItem->getCartableItem()) {
            $cartItem->setName($cartableItem->getName());
            if ($cartableItem instanceof $this->recurringInterface) {
                $rp = new \ReflectionProperty($cartableItem, 'isRecurring');
                $rp->setAccessable(true);
                $rp->setValue($cartableItem, true);
                $rp->setAccessable(false); 
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.11464019851116625, 'fraction_numerical': 0.0019851116625310174, 'mean_word_length': 3.0553319919517103, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '729302', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1152, 'n_words': 250}