<commit_before><?php

namespace Pyz\Zed\Collector\Business\Storage;

use Generated\Shared\Transfer\LocaleTransfer;
use Propel\Runtime\ActiveQuery\Criteria;
use SprykerEngine\Shared\Kernel\Store;
use SprykerEngine\Zed\Touch\Persistence\Propel\Map\SpyTouchTableMap;
use SprykerEngine\Zed\Touch\Persistence\Propel\SpyTouchQuery;
use SprykerFeature\Shared\Collector\Code\KeyBuilder\KeyBuilderTrait;
use SprykerFeature\Zed\Collector\Business\Exporter\AbstractPropelCollectorPlugin;
use SprykerFeature\Zed\Url\Persistence\Propel\Map\SpyRedirectTableMap;
use SprykerFeature\Zed\Url\Persistence\Propel\Map\SpyUrlTableMap;

class RedirectCollector extends AbstractPropelCollectorPlugin
{

    use KeyBuilderTrait;


    protected function getTouchItemType()
    {
        return 'redirect';
    }

    /**
     * @param SpyTouchQuery $baseQuery
     * @param LocaleTransfer $locale
     *
     * @return SpyTouchQuery
     */
    protected function createQuery(SpyTouchQuery $baseQuery, LocaleTransfer $locale)
    {
        $baseQuery->addJoin(
            SpyTouchTableMap::COL_ITEM_ID,
            SpyRedirectTableMap::COL_ID_REDIRECT,
            Criteria::INNER_JOIN
        );

        $baseQuery->addJoin(
            SpyRedirectTableMap::COL_ID_REDIRECT,
            SpyUrlTableMap::COL_FK_RESOURCE_REDIRECT,
            Criteria::INNER_JOIN
        );

        $baseQuery->clearSelectColumns();
        $baseQuery->withColumn(SpyRedirectTableMap::COL_ID_REDIRECT, 'redirect_id');
        $baseQuery->withColumn(SpyUrlTableMap::COL_URL, 'from_url');
        $baseQuery->withColumn(SpyRedirectTableMap::COL_STATUS, 'status');
        $baseQuery->withColumn(SpyRedirectTableMap::COL_TO_URL, 'to_url');

        return $baseQuery;
    }

    /**
     * @param array $resultSet
     * @param LocaleTransfer $locale
     *
     * @return array
     */
    protected function processData($resultSet, LocaleTransfer $locale)
    {
        $processedResultSet = [];
        foreach ($resultSet as $index => $redirect) {
            $redirectKey = $this->generateResourceKey($redirect['redirect_id'], $locale->getLocaleName());
            $processedResultSet[$redirectKey] = [
                'from_url' => $redirect['from_url'],
                'to_url' => $redirect['to_url'],
                'status' => $redirect['status'],
                'id' => $redirect['redirect_id'],
            ];
        }

        return $processedResultSet;
    }

    /**
     * @param string $data
     * @param string $localeName<commit_msg>Redirect collector CR fixes<commit_after><?php

namespace Pyz\Zed\Collector\Business\Storage;

use Generated\Shared\Transfer\LocaleTransfer;
use Propel\Runtime\ActiveQuery\Criteria;
use SprykerEngine\Shared\Kernel\Store;
use SprykerEngine\Zed\Touch\Persistence\Propel\Map\SpyTouchTableMap;
use SprykerEngine\Zed\Touch\Persistence\Propel\SpyTouchQuery;
use SprykerFeature\Shared\Collector\Code\KeyBuilder\KeyBuilderTrait;
use SprykerFeature\Zed\Collector\Business\Exporter\AbstractPropelCollectorPlugin;
use SprykerFeature\Zed\Url\Persistence\Propel\Map\SpyRedirectTableMap;
use SprykerFeature\Zed\Url\Persistence\Propel\Map\SpyUrlTableMap;

class RedirectCollector extends AbstractPropelCollectorPlugin
{
    use KeyBuilderTrait;

    const KEY_FROM_URL = 'from_url';
    const KEY_TO_URL = 'to_url';
    const KEY_STATUS = 'status';
    const KEY_ID = 'id';

    /**
     * @return string
     */
    protected function getTouchItemType()
    {
        return 'redirect';
    }

    /**
     * @param SpyTouchQuery $baseQuery
     * @param LocaleTransfer $locale
     *
     * @return SpyTouchQuery
     */
    protected function createQuery(SpyTouchQuery $baseQuery, LocaleTransfer $locale)
    {
        $baseQuery->addJoin(
            SpyTouchTableMap::COL_ITEM_ID,
            SpyRedirectTableMap::COL_ID_REDIRECT,
            Criteria::INNER_JOIN
        );

        $baseQuery->addJoin(
            SpyRedirectTableMap::COL_ID_REDIRECT,
            SpyUrlTableMap::COL_FK_RESOURCE_REDIRECT,
            Criteria::INNER_JOIN
        );

        $baseQuery->clearSelectColumns();
        $baseQuery->withColumn(SpyRedirectTableMap::COL_ID_REDIRECT, self::KEY_ID);
        $baseQuery->withColumn(SpyUrlTableMap::COL_URL, self::KEY_FROM_URL);
        $baseQuery->withColumn(SpyRedirectTableMap::COL_STATUS, self::KEY_STATUS);
        $baseQuery->withColumn(SpyRedirectTableMap::COL_TO_URL, self::KEY_TO_URL);

        return $baseQuery;
    }

    /**
     * @param array $resultSet
     * @param LocaleTransfer $locale
     *
     * @return array
     */
    protected function processData($resultSet, LocaleTransfer $locale)
    {
        $processedResultSet = [];
        foreach ($resultSet as $redirect) {
            $redirectKey = $this->generateResourceKey($redirect[self::KEY_ID], $locale->getLocaleName());
            $processedResultSet[$redirectKey] = [
                self::KEY_FROM_URL => $redirect[self::KEY_FROM_URL],
                self::KEY_TO_URL => $redirect[self::KEY_TO_URL],
                self::KEY_STATUS => $redirect[self::KEY_STATUS],
                self::KEY_ID => $redirect[self::KEY_ID],
            ];
        }

        return $processedResultSet;
    }

    /**
     * @param string $data
     * @param string $localeName
{'fraction_non_alphanumeric': 0.11136363636363636, 'fraction_numerical': 0.0, 'mean_word_length': 3.1001552795031055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '5627280', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1593, 'n_words': 223}