<commit_before><?php

/*
 *  This file is part of SplashSync Project.
 *
 *  Copyright (C) 2015-2020 Splash Sync  <www.splashsync.com>
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  For the full copyright and license information, please view the LICENSE
 *  file that was distributed with this source code.
 */

namespace Splash\Local\Objects\Product;

use Splash\Core\SplashCore      as Splash;

/**
 * Prestashop Product IDs Encoding/Decoding Functions
 */
trait IdEncoderTrait
{
    /**
     * Convert id_product & id_product_attribute pair
     *
     * @param int $productId   Product Identifier
     * @param int $attributeId Product Combinaison Identifier
     *
     * @return int|string
     */
    public function getUnikId($productId = null, $attributeId = 0)
    {
        if (is_null($productId)) {
            return self::getUnikIdStatic($this->ProductId, $this->AttributeId);
        }

        return self::getUnikIdStatic($productId, $attributeId);
    }

    /**
     * Convert id_product & id_product_attribute pair
     *
     * @param int $productId   Product Identifier
     * @param int $attributeId Product Combinaison Identifier
     *
     * @return string $UnikId
     */
    public static function getUnikIdStatic($productId, $attributeId)
    {
        //====================================================================//
        // No Attribite Id
        if (0 == intval($attributeId)) {
            return (string) $productId;
        }
        //====================================================================//
        // 32 bits Platforms Compatibility
        if ((PHP_INT_SIZE == 4) || !empty(Splash::input('SPLASH_TRAVIS'))) {
            if (($productId > 0xFFFFF) || ($attributeId > 0x7FF)) {

                Splash::log()->warTrace("String Encoding : ". (string) $productId.'@@'.(string) $attributeId);

                return (string) $productId.'@@'.(string) $attributeId;
            }
        }
        //====================================================================//
        // Generate Standard Id
        return (string) ($productId + ($attributeId << 20));
    }

    /**
     * Revert UnikId to decode id_product
     *
     * @param int|string $unikId Product UnikId
     *
     * @return int $id_product
     */<commit_msg>Revert "WIP: MSF Mode on Travis"<commit_after><?php

/*
 *  This file is part of SplashSync Project.
 *
 *  Copyright (C) 2015-2020 Splash Sync  <www.splashsync.com>
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  For the full copyright and license information, please view the LICENSE
 *  file that was distributed with this source code.
 */

namespace Splash\Local\Objects\Product;

use Splash\Core\SplashCore      as Splash;

/**
 * Prestashop Product IDs Encoding/Decoding Functions
 */
trait IdEncoderTrait
{
    /**
     * Convert id_product & id_product_attribute pair
     *
     * @param int $productId   Product Identifier
     * @param int $attributeId Product Combinaison Identifier
     *
     * @return int|string
     */
    public function getUnikId($productId = null, $attributeId = 0)
    {
        if (is_null($productId)) {
            return self::getUnikIdStatic($this->ProductId, $this->AttributeId);
        }

        return self::getUnikIdStatic($productId, $attributeId);
    }

    /**
     * Convert id_product & id_product_attribute pair
     *
     * @param int $productId   Product Identifier
     * @param int $attributeId Product Combinaison Identifier
     *
     * @return string $UnikId
     */
    public static function getUnikIdStatic($productId, $attributeId)
    {
        //====================================================================//
        // No Attribite Id
        if (0 == intval($attributeId)) {
            return (string) $productId;
        }
        //====================================================================//
        // 32 bits Platforms Compatibility
        if ((PHP_INT_SIZE == 4) || !empty(Splash::input('SPLASH_TRAVIS'))) {
            if (($productId > 0xFFFFF) || ($attributeId > 0x7FF)) {

                Splash::log()->warTrace("String Encoding : ". (string) $productId.'@@'.(string) $attributeId);

                return (string) $productId.'@@'.(string) $attributeId;
            }
        }
        //====================================================================//
        // Generate Standard Id
        Splash::log()->warTrace("Standard Encoding : ". (string) ($productId + ($attributeId << 20)));

        return (string) ($productId + ($attributeId << 20));
    }

    /**
     * Revert UnikId to decode id_product
     *
     * @param int|string $unikId Product UnikId
     *
     * @return int $id_product
     */
{'fraction_non_alphanumeric': 0.18820952001593308, 'fraction_numerical': 0.007568213503286198, 'mean_word_length': 2.6953642384105962, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '977702', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1360, 'n_words': 373}