the browser-facing portion of osu!
at master 67 lines 2.2 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6declare(strict_types=1); 7 8namespace Database\Factories; 9 10use App\Models\Spotlight; 11use Carbon\Carbon; 12 13class SpotlightFactory extends Factory 14{ 15 protected $model = Spotlight::class; 16 17 public function configure(): static 18 { 19 return $this->afterMaking(function (Spotlight $spotlight) { 20 $spotlight->end_date ??= $spotlight->start_date?->addMonths(1)->addDays(rand(0, 27)); 21 }); 22 } 23 24 public function definition(): array 25 { 26 return [ 27 'acronym' => 'T'.strtoupper(substr(uniqid(), 8)), 28 'active' => true, 29 'mode_specific' => true, 30 'name' => fn () => $this->faker->realText(40), 31 'start_date' => fn () => $this->faker->dateTimeBetween('-6 years'), 32 'type' => 'test', 33 ]; 34 } 35 36 public function monthly(): static 37 { 38 $chartMonth = Carbon::instance($this->faker->dateTimeBetween('-6 years'))->startOfMonth(); 39 40 return $this->state([ 41 'active' => true, 42 'chart_month' => $chartMonth, 43 'mode_specific' => true, 44 'type' => 'monthly', 45 46 'acronym' => fn (array $attr) => "MONTH{$attr['chart_month']->format('ym')}", 47 'name' => fn (array $attr) => "Spotlight {$attr['chart_month']->format('F Y')}", 48 'start_date' => fn (array $attr) => $attr['chart_month']->copy()->addMonths(1)->addDays(rand(0, 27)), 49 ]); 50 } 51 52 public function bestof(): static 53 { 54 $chartMonth = Carbon::instance($this->faker->dateTimeBetween('-6 years'))->endOfYear(); 55 56 return [ 57 'active' => true, 58 'chart_month' => $chartMonth, 59 'mode_specific' => true, 60 'type' => 'bestof', 61 62 'acronym' => fn (array $attr) => "BEST{$attr['chart_month']->format('Y')}", 63 'name' => fn (array $attr) => "Best of {$attr['chart_month']->format('Y')}", 64 'start_date' => fn (array $attr) => $attr['chart_month']->copy()->addMonths(1)->addDays(rand(0, 27)), 65 ]; 66 } 67}