<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries;

use App\Http\Middleware\RequireScopes;
use Closure;
use Ds\Set;
use Route;

class RouteScopesHelper
{
    public $routes;

    private static $requireScopesPrefix = RequireScopes::class.':';

    public static function keyForMethods(array $methods)
    {
        sort($methods);

        return implode('|', $methods);
    }

    public function fromCsv(string $filename)
    {
        $csv = array_map('str_getcsv', file($filename));

        $routes = array_map(function ($line) use ($csv) {
            $a = array_combine($csv[0], $line);
            $a['methods'] = explode('|', $a['methods']);
            $a['middlewares'] = explode('|', $a['middlewares']);
            $a['scopes'] = array_filter(explode('|', $a['scopes']));

            return $a;
        }, $csv);

        array_shift($routes); // remove column header

        $this->routes = $routes;
    }

    public function fromJson(string $filename)
    {
        $this->routes = json_decode(file_get_contents($filename), true);
    }

    public function loadRoutes()
    {
        $this->routes = [];
        $apiGroup = new Set(Route::getMiddlewareGroups()['api']);
<commit_msg>ensure http kernel and router middleware groups are set<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries;

use App\Http\Middleware\RequireScopes;
use Closure;
use Ds\Set;
use Illuminate\Contracts\Http\Kernel as HttpKernelContract;
use Route;

class RouteScopesHelper
{
    public $routes;

    private static $requireScopesPrefix = RequireScopes::class.':';

    public static function keyForMethods(array $methods)
    {
        sort($methods);

        return implode('|', $methods);
    }

    public function fromCsv(string $filename)
    {
        $csv = array_map('str_getcsv', file($filename));

        $routes = array_map(function ($line) use ($csv) {
            $a = array_combine($csv[0], $line);
            $a['methods'] = explode('|', $a['methods']);
            $a['middlewares'] = explode('|', $a['middlewares']);
            $a['scopes'] = array_filter(explode('|', $a['scopes']));

            return $a;
        }, $csv);

        array_shift($routes); // remove column header

        $this->routes = $routes;
    }

    public function fromJson(string $filename)
    {
        $this->routes = json_decode(file_get_contents($filename), true);
    }

    public function loadRoutes()
    {
        // Force the http kernel singleton to boot if it hasn't.
        // This ensures the router has the middleware groups loaded.
        app(HttpKernelContract::class);

        $this->routes = [];
        $apiGroup = new Set(Route::getMiddlewareGroups()['api']);

{'fraction_non_alphanumeric': 0.14365001632386548, 'fraction_numerical': 0.002611818478615736, 'mean_word_length': 2.943371943371943, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '4650593', 'n_tokens_mistral': 929, 'n_tokens_neox': 919, 'n_words': 238}