<commit_before><?php

namespace WS\ReduceMigrations\Collection;

use WS\ReduceMigrations\Scenario\ScriptScenario;

class MigrationCollection {
    /** @var ScriptScenario[]  */
    private $elements;

    public function __construct($files = array()) {
        foreach ($files as $file) {
            $fileClass = str_replace(".php", "", $file->getName());
            if (!class_exists($fileClass)) {
                include $file->getPath();
            }

            if (!is_subclass_of($fileClass, '\WS\ReduceMigrations\Scenario\ScriptScenario')) {
                continue;
            }
            if (!$fileClass::isValid()) {
                continue;
            }
            $this->elements[] = $fileClass;
        }
    }

    /**
     * @return float|int
     */
    public function getApproximateTime() {
        $time = 0;
        foreach ($this->elements as $element) {
            $time += (double)$element::approximatelyTime();
        }
        return $time;
    }

    /**
     * @return array
     */
    public function groupByPriority() {
        $elements = array();
        $priorities = ScriptScenario::getPriorities();
        foreach ($priorities as $priority) {
            $elements[$priority] = array();
        }
        $elements = array();
        foreach ($this->elements as $key => $element) {
            $elements[$element::priority()][$key] = $element;
        }

        return array_filter($elements);
    }

    /**
     * @return array
     */
    public function toArray() {
        return $this->elements;
    }

    /**
     * @param $migrationHash
     *
     * @return ScriptScenario[]
     */
    public function findByHash($migrationHash) {
        $list = array();
        foreach ($this->elements as $element) {
            if (strpos($element::hash(), $migrationHash) !== 0) {
                continue;
            }
            $list[] = $element;
        }
        return $list;
    }


}
<commit_msg>Исправление ошибки с приоритетом применения миграций<commit_after><?php

namespace WS\ReduceMigrations\Collection;

use WS\ReduceMigrations\Scenario\ScriptScenario;

class MigrationCollection {
    /** @var ScriptScenario[]  */
    private $elements;

    public function __construct($files = array()) {
        foreach ($files as $file) {
            $fileClass = str_replace(".php", "", $file->getName());
            if (!class_exists($fileClass)) {
                include $file->getPath();
            }

            if (!is_subclass_of($fileClass, '\WS\ReduceMigrations\Scenario\ScriptScenario')) {
                continue;
            }
            if (!$fileClass::isValid()) {
                continue;
            }
            $this->elements[] = $fileClass;
        }
    }

    /**
     * @return float|int
     */
    public function getApproximateTime() {
        $time = 0;
        foreach ($this->elements as $element) {
            $time += (double)$element::approximatelyTime();
        }
        return $time;
    }

    /**
     * @return array
     */
    public function groupByPriority() {
        $elements = array();
        $priorities = ScriptScenario::getPriorities();
        foreach ($priorities as $priority) {
            $elements[$priority] = array();
        }

        foreach ($this->elements as $key => $element) {
            $elements[$element::priority()][] = $element;
        }

        return array_filter($elements);
    }

    /**
     * @return array
     */
    public function toArray() {
        $migrations = $this->groupByPriority();
        $result = [];
        array_walk_recursive($migrations, function($item) use (& $result) {
            $result[] = $item;
        });
        return $result;
    }

    /**
     * @param $migrationHash
     *
     * @return ScriptScenario[]
     */
    public function findByHash($migrationHash) {
        $list = array();
        foreach ($this->elements as $element) {
            if (strpos($element::hash(), $migrationHash) !== 0) {
                continue;
            }
            $list[] = $element;
        }
        return $list;
    }


}

{'fraction_non_alphanumeric': 0.14351851851851852, 'fraction_numerical': 0.0009746588693957114, 'mean_word_length': 1.8039617486338797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '657098', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1133, 'n_words': 222}