<commit_before><?php
/**
 *  Map product reverb and prestashop
 *
 * @author <NAME>
 * @copyright Copyright (c) 2017 - <NAME>
 * @license Apache License Version 2.0, January 2004
 * @package Reverb
 */

class ProductMapper
{
    const MAX_CHAR = 255;

    protected $request;

    protected $module;

    /**
     * ReverbProduct constructor.
     * @param \Reverb $module_instance
     *
     */
    public function __construct(\Reverb $module_instance)
    {
        $this->context = \Context::getContext();
        $this->module = $module_instance;
    }

    /**
     *  Validate Product
     *
     * @param $product_ps
     * @throws Exception
     */
    private function validateProductForSync($product_ps)
    {
        if (empty($product_ps['manufacturer_name'])) {
            throw new Exception('Manufacturer is empty.', 1);
        }

        if (empty($product_ps['description'])) {
            throw new Exception('Description is empty.', 1);
        }

        if (strlen($product_ps['manufacturer_name']) > self::MAX_CHAR) {
            throw new Exception('Manufacturer is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['description']) > self::MAX_CHAR) {
            throw new Exception('Description is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['model']) > self::MAX_CHAR) {
            throw new Exception('Model is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['reference']) > self::MAX_CHAR) {
            throw new Exception('Reference is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['name']) > self::MAX_CHAR) {
            throw new Exception('Name is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['finish']) > self::MAX_CHAR) {
            throw new Exception('Finish is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (!is_int($product_ps['year']) || (int)$product_ps['year'] != $product_ps['year'] || strlen($product_ps['year']) != 4) {
            throw new Exception('Year is incorrect', 1);
        }
    }

    /**
     *  Map array prestashop To Reverb's model
     *
     * @param array $product_ps
     * @param bool $productExists
     * @throws Exception
     */
    public function processMapping($product_ps, $productExists)
    {
        $product = new \ProductReverb();

        $this->validateProductForSync($product_ps);

        $product->make = $product_ps['manufacturer_name'];
        $product->model = $product_ps['model'];
        $product->has_inventory = $product_ps['quantity_stock'] > 0 ? 1 : false;
        $product->inventory = $product_ps['quantity_stock'];
        $product->sku = $product_ps['reference'];<commit_msg>delete description control and correct year control<commit_after><?php
/**
 *  Map product reverb and prestashop
 *
 * @author <NAME>
 * @copyright Copyright (c) 2017 - <NAME>
 * @license Apache License Version 2.0, January 2004
 * @package Reverb
 */

class ProductMapper
{
    const MAX_CHAR = 255;

    protected $request;

    protected $module;

    /**
     * ReverbProduct constructor.
     * @param \Reverb $module_instance
     *
     */
    public function __construct(\Reverb $module_instance)
    {
        $this->context = \Context::getContext();
        $this->module = $module_instance;
    }

    /**
     *  Validate Product
     *
     * @param $product_ps
     * @throws Exception
     */
    private function validateProductForSync($product_ps)
    {
        if (empty($product_ps['manufacturer_name'])) {
            throw new Exception('Manufacturer is empty.', 1);
        }

        if (empty($product_ps['description'])) {
            throw new Exception('Description is empty.', 1);
        }

        if (strlen($product_ps['manufacturer_name']) > self::MAX_CHAR) {
            throw new Exception('Manufacturer is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['model']) > self::MAX_CHAR) {
            throw new Exception('Model is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['reference']) > self::MAX_CHAR) {
            throw new Exception('Reference is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['name']) > self::MAX_CHAR) {
            throw new Exception('Name is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if (strlen($product_ps['finish']) > self::MAX_CHAR) {
            throw new Exception('Finish is too long (' . self::MAX_CHAR . ' characters max).', 1);
        }

        if ((int)$product_ps['year'] != $product_ps['year'] || strlen($product_ps['year']) != 4) {
            throw new Exception('Year is incorrect : ' . $product_ps['year'], 1);
        }
    }

    /**
     *  Map array prestashop To Reverb's model
     *
     * @param array $product_ps
     * @param bool $productExists
     * @throws Exception
     */
    public function processMapping($product_ps, $productExists)
    {
        $product = new \ProductReverb();

        $this->validateProductForSync($product_ps);

        $product->make = $product_ps['manufacturer_name'];
        $product->model = $product_ps['model'];
        $product->has_inventory = $product_ps['quantity_stock'] > 0 ? 1 : false;
        $product->inventory = $product_ps['quantity_stock'];
        $product->sku = $product_ps['reference'];
{'fraction_non_alphanumeric': 0.14814814814814814, 'fraction_numerical': 0.0087672213276078, 'mean_word_length': 2.5245901639344264, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 36, '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': '403121', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1602, 'n_words': 380}