<commit_before><?php

namespace CanalTP\MttBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * DistributionListRepositoryRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class DistributionListRepository extends EntityRepository
{
    private function findScheduleKey($scheduleId, $schedules)
    {
        while (list($key, $schedule) = each($schedules)) {
            if ($schedule->stop_point->id == $scheduleId) {
                return $key;
            }
        }
    }

    private function compare($a, $b)
    {
        return $a->stop_point->id === $b->stop_point->id ? 0 : 1;
    }

    public function sortSchedules($schedules, $networkId, $externalRouteId, $reset = false)
    {
        $distributionList = $this->findOneBy(
            array(
                'network' => $networkId,
                'externalRouteId' => $externalRouteId
            )
        );
        $sortedSchedules = array();
        $sortedSchedules['included'] = array();
        $sortedSchedules['excluded'] = array();
        if (empty($distributionList) || $reset == 1) {
            $sortedSchedules['included'] = $schedules;
        }
        if (!empty($distributionList)) {
            $includedStops = $distributionList->getIncludedStops();
            foreach ($includedStops as $scheduleId) {
                $key = $this->findScheduleKey($scheduleId, $schedules);
                if ($reset == false) {
                    $sortedSchedules['included'][] = clone $schedules[$key];
                }
                unset($schedules[$key]);
                reset($schedules);
            }
            $sortedSchedules['excluded'] = $schedules;
            if ($reset == 1) {
                $sortedSchedules['included'] = array_udiff_assoc($sortedSchedules['included'], $schedules, array($this, "compare"));
            }
        }

        return $sortedSchedules;
    }
}<commit_msg>BUGFIX when a stoppoint was deleted in Navitia, distribution list was broken<commit_after><?php

namespace CanalTP\MttBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * DistributionListRepositoryRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class DistributionListRepository extends EntityRepository
{
    private function findScheduleKey($scheduleId, $schedules)
    {
        while (list($key, $schedule) = each($schedules)) {
            if ($schedule->stop_point->id == $scheduleId) {
                return $key;
            }
        }
        return false;
    }

    private function compare($a, $b)
    {
        return $a->stop_point->id === $b->stop_point->id ? 0 : 1;
    }

    public function sortSchedules($schedules, $networkId, $externalRouteId, $reset = false)
    {
        $distributionList = $this->findOneBy(
            array(
                'network' => $networkId,
                'externalRouteId' => $externalRouteId
            )
        );
        $sortedSchedules = array();
        $sortedSchedules['included'] = array();
        $sortedSchedules['excluded'] = array();
        if (empty($distributionList) || $reset == 1) {
            $sortedSchedules['included'] = $schedules;
        }
        if (!empty($distributionList)) {
            $includedStops = $distributionList->getIncludedStops();
            foreach ($includedStops as $scheduleId) {
                $key = $this->findScheduleKey($scheduleId, $schedules);
                if ($key != false) {
                    if ($reset == false) {
                        $sortedSchedules['included'][] = clone $schedules[$key];
                    }
                    unset($schedules[$key]);
                    reset($schedules);
                }
            }
            $sortedSchedules['excluded'] = $schedules;
            if ($reset == 1) {
                $sortedSchedules['included'] = array_udiff_assoc($sortedSchedules['included'], $schedules, array($this, "compare"));
            }
        }

        return $sortedSchedules;
    }
}
{'fraction_non_alphanumeric': 0.13033873343151695, 'fraction_numerical': 0.0019636720667648502, 'mean_word_length': 2.0918057663125946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '2999342', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1084, 'n_words': 224}