<commit_before><?php
namespace Mw\Metamorph\Persistence\Mapping;


/*                                                                        *
 * This script belongs to the TYPO3 Flow package "Mw.Metamorph".          *
 *                                                                        *
 * (C) 2014 <NAME> <<EMAIL>>                        *
 *          Mittwald CM Service GmbH & Co. KG                             *
 *                                                                        */


use Mw\Metamorph\Domain\Model\Extension\AllMatcher;
use Mw\Metamorph\Domain\Model\Extension\ExtensionMatcher;
use Mw\Metamorph\Domain\Model\Extension\PatternExtensionMatcher;
use Mw\Metamorph\Domain\Model\Extension\UnionMatcher;
use Mw\Metamorph\Domain\Model\MorphConfiguration;
use Mw\Metamorph\Exception\InvalidConfigurationException;


class MorphConfigurationProxy extends MorphConfiguration
{



    public function __construct($name, array $data)
    {
        $this->name                  = $name;
        $this->sourceDirectory       = $this->getPropertyFromData($data, 'sourceDirectory');
        $this->extensionMatcher      = $this->buildExtensionMatcher($data);

        $this->tableStructureMode    = $this->getPropertyFromData(
            $data,
            'tableStructureMode',
            FALSE,
            self::TABLE_STRUCTURE_KEEP
        );

        $this->pibaseRefactoringMode = $this->getPropertyFromData(
            $data,
            'pibaseRefactoringMode',
            FALSE,
            self::PIBASE_REFACTOR_CONSERVATIVE
        );
    }



    /**
     * @param array  $data
     * @param string $key
     * @param bool   $required
     * @param mixed  $default
     * @return null
     * @throws InvalidConfigurationException
     */
    private function getPropertyFromData($data, $key, $required = TRUE, $default = NULL)
    {
        if (array_key_exists($key, $data))
        {
            return $data[$key];
        }
        else
        {
            if ($required)
            {
                throw new InvalidConfigurationException(
                    'Expected property "' . $key . '" in morph configuration!',
                    1411832225
                );
            }
            return $default;
        }
    }



    /**
     * @param array $data
     * @return ExtensionMatcher
     * @throws InvalidConfigurationException
     */
    private function buildExtensionMatcher(array $data)
    {
        $rootExtensionMatcher = new AllMatcher();
        $extensionMatchers    = [];

        foreach ($data['extensions'] as $extensionConfiguration)
        {
            if (array_key_exists('pattern', $extensionConfiguration))
            {
                $extensionMatchers[] = new PatternExtensionMatcher($extensionConfiguration['pattern']);
            }

            throw new InvalidConfigurationException(
                'Invalid extension matcher configuration: ' . json_encode($extensionConfiguration),
                1399996413
            );
        }

        if (count($extensionMatchers) > 0)
        {
            $rootExtensionMatcher = new UnionMatcher($extensionMatchers);
            return $rootExtensionMatcher;
        }
        return $rootExtensionMatcher;
    }


}<commit_msg>Allow NULL extension list in morphs.<commit_after><?php
namespace Mw\Metamorph\Persistence\Mapping;


/*                                                                        *
 * This script belongs to the TYPO3 Flow package "Mw.Metamorph".          *
 *                                                                        *
 * (C) 2014 <NAME> <<EMAIL>>                        *
 *          Mittwald CM Service GmbH & Co. KG                             *
 *                                                                        */


use Mw\Metamorph\Domain\Model\Extension\AllMatcher;
use Mw\Metamorph\Domain\Model\Extension\ExtensionMatcher;
use Mw\Metamorph\Domain\Model\Extension\PatternExtensionMatcher;
use Mw\Metamorph\Domain\Model\Extension\UnionMatcher;
use Mw\Metamorph\Domain\Model\MorphConfiguration;
use Mw\Metamorph\Exception\InvalidConfigurationException;


class MorphConfigurationProxy extends MorphConfiguration
{



    public function __construct($name, array $data)
    {
        $this->name                  = $name;
        $this->sourceDirectory       = $this->getPropertyFromData($data, 'sourceDirectory');
        $this->extensionMatcher      = $this->buildExtensionMatcher($data);

        $this->tableStructureMode    = $this->getPropertyFromData(
            $data,
            'tableStructureMode',
            FALSE,
            self::TABLE_STRUCTURE_KEEP
        );

        $this->pibaseRefactoringMode = $this->getPropertyFromData(
            $data,
            'pibaseRefactoringMode',
            FALSE,
            self::PIBASE_REFACTOR_CONSERVATIVE
        );
    }



    /**
     * @param array  $data
     * @param string $key
     * @param bool   $required
     * @param mixed  $default
     * @return null
     * @throws InvalidConfigurationException
     */
    private function getPropertyFromData($data, $key, $required = TRUE, $default = NULL)
    {
        if (array_key_exists($key, $data))
        {
            return $data[$key];
        }
        else
        {
            if ($required)
            {
                throw new InvalidConfigurationException(
                    'Expected property "' . $key . '" in morph configuration!',
                    1411832225
                );
            }
            return $default;
        }
    }



    /**
     * @param array $data
     * @return ExtensionMatcher
     * @throws InvalidConfigurationException
     */
    private function buildExtensionMatcher(array $data)
    {
        $rootExtensionMatcher = new AllMatcher();
        $extensionMatchers    = [];

        foreach ((array)$data['extensions'] as $extensionConfiguration)
        {
            if (array_key_exists('pattern', $extensionConfiguration))
            {
                $extensionMatchers[] = new PatternExtensionMatcher($extensionConfiguration['pattern']);
            }

            throw new InvalidConfigurationException(
                'Invalid extension matcher configuration: ' . json_encode($extensionConfiguration),
                1399996413
            );
        }

        if (count($extensionMatchers) > 0)
        {
            $rootExtensionMatcher = new UnionMatcher($extensionMatchers);
            return $rootExtensionMatcher;
        }
        return $rootExtensionMatcher;
    }


}
{'fraction_non_alphanumeric': 0.09341664126790612, 'fraction_numerical': 0.007924413288631514, 'mean_word_length': 1.61578318055002, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1694544', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1551, 'n_words': 305}