<commit_before><?php

/**
 * (c) 2011 - ∞ Vespolina Project http://www.vespolina-project.org
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Vespolina\Product\Manager;

use Vespolina\Exception\InvalidConfigurationException;

use Vespolina\Entity\Channel\ChannelInterface;
use Vespolina\Entity\Product\AttributeInterface;
use Vespolina\Entity\Product\OptionGroupInterface;
use Vespolina\Entity\Product\ProductInterface;
use Vespolina\Entity\Identifier\IdentifierInterface;
use Vespolina\Entity\Identifier\SKUIdentifier;
use Vespolina\Product\Gateway\ProductGatewayInterface;
use Vespolina\Product\Handler\MerchandiseHandlerInterface;
use Vespolina\Product\Handler\ProductHandlerInterface;
use Vespolina\Product\Manager\ProductManagerInterface;
use Vespolina\Specification\FilterSpecification;
use Vespolina\Specification\IdSpecification;
use Vespolina\Specification\SpecificationInterface;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ProductManager implements ProductManagerInterface
{
    protected $classMapping;
    protected $configuration;
    protected $gateways;
    protected $identifiers;
    protected $productHandlers;
    protected $merchandiseHandlers;
    protected $attributeClass;
    protected $merchandiseClass;
    protected $optionClass;
    protected $productClass;

    /**
     * Create a new product manager
     *
     * Pass in the default gateway, product class map and an optional configuration
     *
     * @param ProductGatewayInterface $defaultGateway
     * @param array $classMapping
     * @param array $configuration
     *
     * @throws \Vespolina\Exception\InvalidConfigurationException
     */
    public function __construct(ProductGatewayInterface $defaultGateway, array $classMapping, array $configuration = array())
    {
        // Prepare the class map
        $missingClasses = array();
        foreach (array('attribute', 'merchandise', 'option', 'product') as $class) {
            $class = $class . 'Class';
            if (isset($classMapping[$class])) {

                if (!class_exists($classMapping[$class]))
                    throw new InvalidConfigurationException(sprintf("Class '%s' not found as '%s'", $classMapping[$class], $class));

                $this->{$class} = $classMapping[$class];
                continue;
            }
            $missingClasses[] = $class;
        }

        if (count($missingClasses)) {
            throw new InvalidConfigurationException(sprintf("The following partner classes are missing from configuration: %s", join(', ', $missingClasses)));
        }
        $this->classMapping = $classMapping;

        // Prepare the manager configuration
        $defaultConfiguration = array(
            'multiChannel' => false     // Switch off / on product merchandise support
        );

        $this->configuration = array_merge($configuration, $defaultConfiguration);

        // Setup the default product gateway
        $this->gateways = array('default' => $defaultGateway);
        $this->productHandlers = array();
    }

    public function addAttributeToProduct(ProductInterface $product, $attribute, $name = null)
    {
        if (!$attribute instanceof AttributeInterface) {
            if (is_array($attribute)) {
                $type = key($attribute);
                $name = $attribute[$type];
            } else {
                $type = $attribute;
            }
            $attribute  = new $this->attributeClass;
            $attribute->setType($type);
            $attribute->setName($name);
        }

        $product->addAttribute($attribute);
    }

    public function addOptionToProduct(ProductInterface $product, $type, $value = null)
    {

    }

    /**
     * @inheritdoc
     */
    public function addProductHandler(ProductHandlerInterface $handler)
    {
        $type = $handler->getType();
        $this->productHandlers[$type] = $handler;
    }

    /**
     * @inheritdoc
     */
    public function addMerchandiseHandler(MerchandiseHandlerInterface $handler)
    {
        $type = $handler->getType();
        $this->merchandiseHandlers[$type] = $handler;
    }

    /**
     * @inheritdoc
     */
    public function createAttribute($type, $name)
    {
        /** @var $attribute \Vespolina\Entity\Product\AttributeInterface */
        $attribute = new $this->classMapping['attribute'];
        $attribute->setType($type);
        $attribute->setName($name);

        return $attribute;
    }

    /**
     * @inheritdoc
     */
    public function createIdentifier($name)
    {
        $name = strtolower($name);

        return new $this->identifiers[$name];
    }

    /**
     * @inheritdoc
     */
    public function createOption($type, $value)
    {
        $optionClass = $this->getOptionClass();
        $option = new $optionClass;
        $option->setType($type);
        $option->setValue($value);

        return $option;
    }

    /**
     * @inheritdoc
     */
    public function createOptionGroup()
    {
        return new $this->classMapping['option'];
    }

    /**
     * @inheritdoc
     */
    public function createProduct($type = 'default', $parent = null)
    {
        if (isset($this->productHandlers[$type])) {

            return $this->productHandlers[$type]->createProduct($parent);
        }
<commit_msg>Vespolina: store-setup setValue () error<commit_after><?php

/**
 * (c) 2011 - ∞ Vespolina Project http://www.vespolina-project.org
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Vespolina\Product\Manager;

use Vespolina\Exception\InvalidConfigurationException;

use Vespolina\Entity\Channel\ChannelInterface;
use Vespolina\Entity\Product\AttributeInterface;
use Vespolina\Entity\Product\OptionGroupInterface;
use Vespolina\Entity\Product\ProductInterface;
use Vespolina\Entity\Identifier\IdentifierInterface;
use Vespolina\Entity\Identifier\SKUIdentifier;
use Vespolina\Product\Gateway\ProductGatewayInterface;
use Vespolina\Product\Handler\MerchandiseHandlerInterface;
use Vespolina\Product\Handler\ProductHandlerInterface;
use Vespolina\Product\Manager\ProductManagerInterface;
use Vespolina\Specification\FilterSpecification;
use Vespolina\Specification\IdSpecification;
use Vespolina\Specification\SpecificationInterface;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 */
class ProductManager implements ProductManagerInterface
{
    protected $classMapping;
    protected $configuration;
    protected $gateways;
    protected $identifiers;
    protected $productHandlers;
    protected $merchandiseHandlers;
    protected $attributeClass;
    protected $merchandiseClass;
    protected $optionClass;
    protected $productClass;

    /**
     * Create a new product manager
     *
     * Pass in the default gateway, product class map and an optional configuration
     *
     * @param ProductGatewayInterface $defaultGateway
     * @param array $classMapping
     * @param array $configuration
     *
     * @throws \Vespolina\Exception\InvalidConfigurationException
     */
    public function __construct(ProductGatewayInterface $defaultGateway, array $classMapping, array $configuration = array())
    {
        // Prepare the class map
        $missingClasses = array();
        foreach (array('attribute', 'merchandise', 'option', 'product') as $class) {
            $class = $class . 'Class';
            if (isset($classMapping[$class])) {

                if (!class_exists($classMapping[$class]))
                    throw new InvalidConfigurationException(sprintf("Class '%s' not found as '%s'", $classMapping[$class], $class));

                $this->{$class} = $classMapping[$class];
                continue;
            }
            $missingClasses[] = $class;
        }

        if (count($missingClasses)) {
            throw new InvalidConfigurationException(sprintf("The following partner classes are missing from configuration: %s", join(', ', $missingClasses)));
        }
        $this->classMapping = $classMapping;

        // Prepare the manager configuration
        $defaultConfiguration = array(
            'multiChannel' => false     // Switch off / on product merchandise support
        );

        $this->configuration = array_merge($configuration, $defaultConfiguration);

        // Setup the default product gateway
        $this->gateways = array('default' => $defaultGateway);
        $this->productHandlers = array();
    }

    public function addAttributeToProduct(ProductInterface $product, $attribute, $name = null)
    {
        if (!$attribute instanceof AttributeInterface) {
            if (is_array($attribute)) {
                $type = key($attribute);
                $name = $attribute[$type];
            } else {
                $type = $attribute;
            }
            $attribute  = new $this->attributeClass;
            $attribute->setType($type);
            $attribute->setName($name);
        }

        $product->addAttribute($attribute);
    }

    public function addOptionToProduct(ProductInterface $product, $type, $value = null)
    {

    }

    /**
     * @inheritdoc
     */
    public function addProductHandler(ProductHandlerInterface $handler)
    {
        $type = $handler->getType();
        $this->productHandlers[$type] = $handler;
    }

    /**
     * @inheritdoc
     */
    public function addMerchandiseHandler(MerchandiseHandlerInterface $handler)
    {
        $type = $handler->getType();
        $this->merchandiseHandlers[$type] = $handler;
    }

    /**
     * @inheritdoc
     */
    public function createAttribute($type, $name)
    {
        /** @var $attribute \Vespolina\Entity\Product\AttributeInterface */
        $attribute = new $this->classMapping['attribute'];
        $attribute->setType($type);
        $attribute->setName($name);

        return $attribute;
    }

    /**
     * @inheritdoc
     */
    public function createIdentifier($name)
    {
        $name = strtolower($name);

        return new $this->identifiers[$name];
    }

    /**
     * @inheritdoc
     */
    public function createOption($type, $value)
    {
        $optionClass = $this->getOptionClass();
        $option = new $optionClass;
        $option->setType($type);
        $option->setIndex($value);

        return $option;
    }

    /**
     * @inheritdoc
     */
    public function createOptionGroup()
    {
        return new $this->classMapping['option'];
    }

    /**
     * @inheritdoc
     */
    public function createProduct($type = 'default', $parent = null)
    {
        if (isset($this->productHandlers[$type])) {

            return $this->productHandlers[$type]->createProduct($parent);
        }

{'fraction_non_alphanumeric': 0.11873668611651385, 'fraction_numerical': 0.0007409465592294156, 'mean_word_length': 2.7337482710926695, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 67, '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': '7652515', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2815, 'n_words': 623}