<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.

namespace App\Http\Controllers;

use App\Models\Beatmap;
use App\Models\Country;
use App\Models\CountryStatistics;
use App\Models\Spotlight;
use App\Models\UserStatistics;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

/**
 * @group Ranking
 */
class RankingController extends Controller
{
    private $country;
    private $params;
    private $friendsOnly;

    const PAGE_SIZE = 50;
    const MAX_RESULTS = 10000;
    const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
    const SPOTLIGHT_TYPES = ['charts'];

    public function __construct()
    {
        parent::__construct();

        $this->middleware(function ($request, $next) {
            $this->params = get_params(array_merge($request->all(), $request->route()->parameters()), null, [
                'country', // overridden later for view
                'filter',
                'mode',
                'spotlight:int', // will be overriden by spotlight object for view
                'type',
            ]);

            // these parts of the route are optional.
            $mode = $this->params['mode'] ?? null;
            $type = $this->params['type'] ?? null;

            $this->params['filter'] = $this->params['filter'] ?? null;
            $this->friendsOnly = $this->params['filter'] === 'friends';

            view()->share('hasPager', !in_array($type, static::SPOTLIGHT_TYPES, true));
            view()->share('spotlight', null); // so variable capture in selector function doesn't die when spotlight is null.
            view()->share($this->params); // won't set null values

            if ($mode === null) {
                return ujs_redirect(route('rankings', ['mode' => 'osu', 'type' => 'performance']));
            }

            if (!Beatmap::isModeValid($mode)) {
                abort(404);
            }
<commit_msg>no friends if not logged in<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.

namespace App\Http\Controllers;

use App\Models\Beatmap;
use App\Models\Country;
use App\Models\CountryStatistics;
use App\Models\Spotlight;
use App\Models\UserStatistics;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

/**
 * @group Ranking
 */
class RankingController extends Controller
{
    private $country;
    private $params;
    private $friendsOnly;

    const PAGE_SIZE = 50;
    const MAX_RESULTS = 10000;
    const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
    const SPOTLIGHT_TYPES = ['charts'];

    public function __construct()
    {
        parent::__construct();

        $this->middleware(function ($request, $next) {
            $this->params = get_params(array_merge($request->all(), $request->route()->parameters()), null, [
                'country', // overridden later for view
                'filter',
                'mode',
                'spotlight:int', // will be overriden by spotlight object for view
                'type',
            ]);

            // these parts of the route are optional.
            $mode = $this->params['mode'] ?? null;
            $type = $this->params['type'] ?? null;

            $this->params['filter'] = $this->params['filter'] ?? null;
            $this->friendsOnly = auth()->check() && $this->params['filter'] === 'friends';

            view()->share('hasPager', !in_array($type, static::SPOTLIGHT_TYPES, true));
            view()->share('spotlight', null); // so variable capture in selector function doesn't die when spotlight is null.
            view()->share($this->params); // won't set null values

            if ($mode === null) {
                return ujs_redirect(route('rankings', ['mode' => 'osu', 'type' => 'performance']));
            }

            if (!Beatmap::isModeValid($mode)) {
                abort(404);
            }

{'fraction_non_alphanumeric': 0.1467934650085345, 'fraction_numerical': 0.005852231163130944, 'mean_word_length': 2.47921967769296, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 42, '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': '4880531', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1126, 'n_words': 312}