<commit_before><?php
namespace Yoanm\InitRepositoryWithComposer\Application\Serializer\Normalizer;

use Yoanm\InitRepositoryWithComposer\Domain\Model\Configuration;

class ConfigurationNormalizer
{
    const KEY_NAME = 'name';
    const KEY_TYPE = 'type';
    const KEY_LICENSE = 'license';
    const KEY_VERSION = 'version';
    const KEY_DESCRIPTION = 'description';
    const KEY_KEYWORDS = 'keywords';
    const KEY_AUTHORS = 'authors';
    const KEY_PROVIDE = 'provide';
    const KEY_SUGGEST = 'suggest';
    const KEY_SUPPORT = 'support';
    const KEY_REQUIRE = 'require';
    const KEY_REQUIRE_DEV = 'require-dev';
    const KEY_AUTOLOAD = 'autoload';
    const KEY_AUTOLOAD_DEV = 'autoload-dev';
    const KEY_SCRIPT = 'script';

    /** @var AuthorListNormalizer */
    private $authorListNormalizer;
    /** @var PackageListNormalizer */
    private $packageListNormalizer;
    /** @var SuggestedPackageListNormalizer */
    private $suggestedPackageListNormalizer;
    /** @var SupportListNormalizer */
    private $supportListNormalizer;
    /** @var AutoloadListNormalizer */
    private $autoloadListNormalizer;
    /** @var ScriptListNormalizer */
    private $scriptListNormalizer;

    public function __construct(
        AuthorListNormalizer $authorListNormalizer,
        PackageListNormalizer $packageListNormalizer,
        SuggestedPackageListNormalizer $suggestedPackageListNormalizer,
        SupportListNormalizer $supportListNormalizer,
        AutoloadListNormalizer $autoloadListNormalizer,
        ScriptListNormalizer $scriptListNormalizer
    ) {
        $this->authorListNormalizer = $authorListNormalizer;
        $this->packageListNormalizer = $packageListNormalizer;
        $this->suggestedPackageListNormalizer = $suggestedPackageListNormalizer;
        $this->supportListNormalizer = $supportListNormalizer;
        $this->autoloadListNormalizer = $autoloadListNormalizer;
        $this->scriptListNormalizer = $scriptListNormalizer;
    }

    public function normalize(Configuration $configuration)
    {
        $normalizedAuthorList = $this->authorListNormalizer->normalize(
            $configuration->getAuthorList()
        );
        $normalizedProvidedPackageList = $this->packageListNormalizer->normalize(
            $configuration->getProvidedPackageList()
        );
        $normalizedSuggestedPackageList = $this->suggestedPackageListNormalizer->normalize(
            $configuration->getSuggestedPackageList()
        );
        $normalizedSupportList = $this->supportListNormalizer->normalize(
            $configuration->getSupportList()
        );
        $normalizedRequiredPackageList = $this->packageListNormalizer->normalize(
            $configuration->getRequiredPackageList()
        );
        $normalizedRequiredDevPackageList = $this->packageListNormalizer->normalize(
            $configuration->getRequiredDevPackageList()
        );
        $normalizedAutoloadList = $this->autoloadListNormalizer->normalize(
            $configuration->getAutoloadList()
        );
        $normalizedAutoloadDevList = $this->autoloadListNormalizer->normalize(
            $configuration->getAutoloadDevList()
        );
        $normalizedScriptList = $this->scriptListNormalizer->normalize(
            $configuration->getScriptList()
        );

        $normalizedConfiguration = [
            self::KEY_NAME => $configuration->getPackageName(),
            self::KEY_TYPE =>$configuration->getType(),
            self::KEY_LICENSE => $configuration->getLicense()
        ];

        if ($configuration->getPackageVersion()) {
            $normalizedConfiguration[self::KEY_VERSION] = $configuration->getPackageVersion();
        }
        if ($configuration->getDescription()) {
            $normalizedConfiguration[self::KEY_DESCRIPTION] = $configuration->getDescription();
        }
        if (count($configuration->getKeywordList())) {
            $normalizedConfiguration[self::KEY_KEYWORDS] = $configuration->getKeywordList();
        }
        if (count($normalizedAuthorList)) {
            $normalizedConfiguration[self::KEY_AUTHORS] = $normalizedAuthorList;
        }
        if (count($normalizedProvidedPackageList)) {
            $normalizedConfiguration[self::KEY_PROVIDE] = $normalizedProvidedPackageList;
        }
        if (count($normalizedSuggestedPackageList)) {
            $normalizedConfiguration[self::KEY_SUGGEST] = $normalizedSuggestedPackageList;
        }
        if (count($normalizedSupportList)) {
            $normalizedConfiguration[self::KEY_SUPPORT] = $normalizedSupportList;
        }
        if (count($normalizedRequiredPackageList)) {
            $normalizedConfiguration[self::KEY_REQUIRE] = $normalizedRequiredPackageList;
        }
        if (count($normalizedRequiredDevPackageList)) {
            $normalizedConfiguration[self::KEY_REQUIRE_DEV] = $normalizedRequiredDevPackageList;
        }
        if (count($normalizedAutoloadList)) {
            $normalizedConfiguration[self::KEY_AUTOLOAD] = $normalizedAutoloadList;
        }
        if (count($normalizedAutoloadDevList)) {
            $normalizedConfiguration[self::KEY_AUTOLOAD_DEV] = $normalizedAutoloadDevList;
        }
        if (count($normalizedScriptList)) {
            $normalizedConfiguration[self::KEY_SCRIPT] = $normalizedScriptList;
        }

        return $normalizedConfiguration;
    }
}<commit_msg>Reduce complexity<commit_after><?php
namespace Yoanm\InitRepositoryWithComposer\Application\Serializer\Normalizer;

use Yoanm\InitRepositoryWithComposer\Domain\Model\Configuration;

class ConfigurationNormalizer
{
    const KEY_NAME = 'name';
    const KEY_TYPE = 'type';
    const KEY_LICENSE = 'license';
    const KEY_VERSION = 'version';
    const KEY_DESCRIPTION = 'description';
    const KEY_KEYWORDS = 'keywords';
    const KEY_AUTHORS = 'authors';
    const KEY_PROVIDE = 'provide';
    const KEY_SUGGEST = 'suggest';
    const KEY_SUPPORT = 'support';
    const KEY_REQUIRE = 'require';
    const KEY_REQUIRE_DEV = 'require-dev';
    const KEY_AUTOLOAD = 'autoload';
    const KEY_AUTOLOAD_DEV = 'autoload-dev';
    const KEY_SCRIPT = 'script';

    /** @var AuthorListNormalizer */
    private $authorListNormalizer;
    /** @var PackageListNormalizer */
    private $packageListNormalizer;
    /** @var SuggestedPackageListNormalizer */
    private $suggestedPackageListNormalizer;
    /** @var SupportListNormalizer */
    private $supportListNormalizer;
    /** @var AutoloadListNormalizer */
    private $autoloadListNormalizer;
    /** @var ScriptListNormalizer */
    private $scriptListNormalizer;

    public function __construct(
        AuthorListNormalizer $authorListNormalizer,
        PackageListNormalizer $packageListNormalizer,
        SuggestedPackageListNormalizer $suggestedPackageListNormalizer,
        SupportListNormalizer $supportListNormalizer,
        AutoloadListNormalizer $autoloadListNormalizer,
        ScriptListNormalizer $scriptListNormalizer
    ) {
        $this->authorListNormalizer = $authorListNormalizer;
        $this->packageListNormalizer = $packageListNormalizer;
        $this->suggestedPackageListNormalizer = $suggestedPackageListNormalizer;
        $this->supportListNormalizer = $supportListNormalizer;
        $this->autoloadListNormalizer = $autoloadListNormalizer;
        $this->scriptListNormalizer = $scriptListNormalizer;
    }

    public function normalize(Configuration $configuration)
    {
        $normalizedConfiguration = [
            self::KEY_NAME => $configuration->getPackageName(),
            self::KEY_TYPE =>$configuration->getType(),
            self::KEY_LICENSE => $configuration->getLicense()
        ];

        // package version
        $normalizedConfiguration = $this->appendIfDefined(
            $normalizedConfiguration,
            $configuration->getPackageVersion(),
            self::KEY_VERSION
        );
        // description
        $normalizedConfiguration = $this->appendIfDefined(
            $normalizedConfiguration,
            $configuration->getDescription(),
            self::KEY_DESCRIPTION
        );
        // keywords
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $configuration->getKeywordList(),
            self::KEY_KEYWORDS
        );
        // authors
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->authorListNormalizer->normalize($configuration->getAuthorList()),
            self::KEY_AUTHORS
        );
        // provide
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->packageListNormalizer->normalize($configuration->getProvidedPackageList()),
            self::KEY_PROVIDE
        );
        // suggest
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->suggestedPackageListNormalizer->normalize($configuration->getSuggestedPackageList()),
            self::KEY_SUGGEST
        );
        // support
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->supportListNormalizer->normalize($configuration->getSupportList()),
            self::KEY_SUPPORT
        );
        // require
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->packageListNormalizer->normalize($configuration->getRequiredPackageList()),
            self::KEY_REQUIRE
        );
        // require-dev
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->packageListNormalizer->normalize($configuration->getRequiredDevPackageList()),
            self::KEY_REQUIRE_DEV
        );
        // autoload
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->autoloadListNormalizer->normalize($configuration->getAutoloadList()),
            self::KEY_AUTOLOAD
        );
        // autoload-dev
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->autoloadListNormalizer->normalize($configuration->getAutoloadDevList()),
            self::KEY_AUTOLOAD_DEV
        );
        // script
        $normalizedConfiguration = $this->appendIfNotEmpty(
            $normalizedConfiguration,
            $this->scriptListNormalizer->normalize($configuration->getScriptList()),
            self::KEY_SCRIPT
        );

        return $normalizedConfiguration;
    }

    /**
     * @param array  $normalizedConfiguration
     * @param array  $list
     * @param string $key
     *
     * @return array
     */
    protected function appendIfNotEmpty(array $normalizedConfiguration, array $list, $key)
    {
        if (count($list)) {
            $normalizedConfiguration[$key] = $list;
        }

        return $normalizedConfiguration;
    }

    /**
     * @param array  $normalizedConfiguration
     * @param string $value
     * @param string $key
     *
     * @return array
     */
    protected function appendIfDefined(array $normalizedConfiguration, $value, $key)
    {
        if ($value) {
            $normalizedConfiguration[$key] = $value;
        }

        return $normalizedConfiguration;
    }
}
{'fraction_non_alphanumeric': 0.10193321616871705, 'fraction_numerical': 0.0, 'mean_word_length': 2.9682705718270572, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, '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': '3109177', 'n_tokens_mistral': 2962, 'n_tokens_neox': 2937, 'n_words': 428}