<commit_before><?php
namespace Ttree\JobButler\Domain\Repository;

/*
 * This file is part of the Ttree.JobButler package.
 *
 * (c) Contributors of the project and the ttree team - www.ttree.ch
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Ttree\JobButler\Domain\Model\JobConfigurationInterface;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Object\ObjectManagerInterface;
use TYPO3\Flow\Utility\Unicode\Functions;

/**
 * Job Configuration Repository
 *
 * @Flow\Scope("singleton")
 */
class JobConfigurationRepository
{

    const JOB_CONFIGURATION_INTERFACE = 'Ttree\JobButler\Domain\Model\JobConfigurationInterface';

    /**
     * @Flow\Inject
     * @var ObjectManagerInterface
     */
    protected $objectManager;

    /**
     * Return all Jobs grouped by tags
     *
     * A single Job can be attached to multiple Tags.
     *
     * @return array
     */
    public function findAll()
    {
        $jobConfigurations = [];

        foreach (self::getAvailableJobConfigurations($this->objectManager) as $jobConfiguration) {
            /** @var JobConfigurationInterface $implementation */
            $implementation = $this->objectManager->get($jobConfiguration['implementation']);
            $job = [
                'name' => $implementation->getName(),
                'implementation' => $implementation,
                'tags' => $implementation->getTags()
            ];
            $jobConfigurations[] = $job;
        }

        usort($jobConfiguration, function($a, $b) {
            return natsort($a['name'], $b['name']);
        });

        return $this->orderJobs($jobConfigurations);
    }

    /**
     * @param string
     * @return JobConfigurationInterface
     */
    public function findOneByIdentifier($identifier)
    {
        $jobs = $this->getAvailableJobConfigurations($this->objectManager);
        foreach ($jobs as $job) {
            /** @var JobConfigurationInterface $job */
            if ($job['implementation'] !== $identifier) {
                continue;
            }
            return new $job['implementation'];
        }
    }

    /**
     * Returns a map of all available jobs configuration
     *
     * @param ObjectManagerInterface $objectManager
     * @return array Array of available jobs configuration
     * @Flow\CompileStatic
     */
    public static function getAvailableJobConfigurations($objectManager)
    {
        $reflectionService = $objectManager->get('TYPO3\Flow\Reflection\ReflectionService');

        $result = [];

        foreach ($reflectionService->getAllImplementationClassNamesForInterface(self::JOB_CONFIGURATION_INTERFACE) as $implementation) {
            $result[$implementation] = [
                'implementation' => $implementation
            ];
        }

        return $result;
    }

    /**
     * Order current job list, order by name by default
     *
     * @param array $jobConfigurations
     * @param string $orderBy
     * @return array
     */
    protected function orderJobs(array $jobConfigurations, $orderBy = 'name')
    {
        usort($jobConfigurations, function ($a, $b) use ($orderBy) {
            $a = Functions::strtolower(trim($a[$orderBy]));
            $b = Functions::strtolower(trim($b[$orderBy]));
            if ($a == $b) {
                return 0;
            }
            return ($a < $b) ? -1 : 1;
        });

        $result = [];
        foreach ($jobConfigurations as $jobConfiguration) {
            $result[] = $jobConfiguration['implementation'];
        }

        return $result;
    }
}
<commit_msg>BUGFIX: Usort uses wrong variable to sort<commit_after><?php
namespace Ttree\JobButler\Domain\Repository;

/*
 * This file is part of the Ttree.JobButler package.
 *
 * (c) Contributors of the project and the ttree team - www.ttree.ch
 *
 * This package is Open Source Software. For the full copyright and license
 * information, please view the LICENSE file which was distributed with this
 * source code.
 */

use Ttree\JobButler\Domain\Model\JobConfigurationInterface;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Object\ObjectManagerInterface;
use TYPO3\Flow\Utility\Unicode\Functions;

/**
 * Job Configuration Repository
 *
 * @Flow\Scope("singleton")
 */
class JobConfigurationRepository
{

    const JOB_CONFIGURATION_INTERFACE = 'Ttree\JobButler\Domain\Model\JobConfigurationInterface';

    /**
     * @Flow\Inject
     * @var ObjectManagerInterface
     */
    protected $objectManager;

    /**
     * Return all Jobs grouped by tags
     *
     * A single Job can be attached to multiple Tags.
     *
     * @return array
     */
    public function findAll()
    {
        $jobConfigurations = [];

        foreach (self::getAvailableJobConfigurations($this->objectManager) as $jobConfiguration) {
            /** @var JobConfigurationInterface $implementation */
            $implementation = $this->objectManager->get($jobConfiguration['implementation']);
            $job = [
                'name' => $implementation->getName(),
                'implementation' => $implementation,
                'tags' => $implementation->getTags()
            ];
            $jobConfigurations[] = $job;
        }

        usort($jobConfigurations, function($a, $b) {
            return natsort($a['name'], $b['name']);
        });

        return $this->orderJobs($jobConfigurations);
    }

    /**
     * @param string
     * @return JobConfigurationInterface
     */
    public function findOneByIdentifier($identifier)
    {
        $jobs = $this->getAvailableJobConfigurations($this->objectManager);
        foreach ($jobs as $job) {
            /** @var JobConfigurationInterface $job */
            if ($job['implementation'] !== $identifier) {
                continue;
            }
            return new $job['implementation'];
        }
    }

    /**
     * Returns a map of all available jobs configuration
     *
     * @param ObjectManagerInterface $objectManager
     * @return array Array of available jobs configuration
     * @Flow\CompileStatic
     */
    public static function getAvailableJobConfigurations($objectManager)
    {
        $reflectionService = $objectManager->get('TYPO3\Flow\Reflection\ReflectionService');

        $result = [];

        foreach ($reflectionService->getAllImplementationClassNamesForInterface(self::JOB_CONFIGURATION_INTERFACE) as $implementation) {
            $result[$implementation] = [
                'implementation' => $implementation
            ];
        }

        return $result;
    }

    /**
     * Order current job list, order by name by default
     *
     * @param array $jobConfigurations
     * @param string $orderBy
     * @return array
     */
    protected function orderJobs(array $jobConfigurations, $orderBy = 'name')
    {
        usort($jobConfigurations, function ($a, $b) use ($orderBy) {
            $a = Functions::strtolower(trim($a[$orderBy]));
            $b = Functions::strtolower(trim($b[$orderBy]));
            if ($a == $b) {
                return 0;
            }
            return ($a < $b) ? -1 : 1;
        });

        $result = [];
        foreach ($jobConfigurations as $jobConfiguration) {
            $result[] = $jobConfiguration['implementation'];
        }

        return $result;
    }
}

{'fraction_non_alphanumeric': 0.11843349088453747, 'fraction_numerical': 0.0018906144496961513, 'mean_word_length': 2.383280036546368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5828015', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1925, 'n_words': 460}