Skip to content

Commit

Permalink
Merge pull request #11343 from nanaya/macro-hint
Browse files Browse the repository at this point in the history
Type model macro related settings
  • Loading branch information
notbakaneko authored Jul 23, 2024
2 parents 0c0510a + 4873cbe commit 5dd1476
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
9 changes: 4 additions & 5 deletions app/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class Model extends BaseModel

protected $connection = 'mysql';
protected $guarded = [];
protected $macros;
protected array $macros = [];
protected $primaryKeys;

public static function booted()
Expand All @@ -47,15 +47,14 @@ public function getKey()
return $this->getRawAttribute($this->primaryKey);
}

public function getMacros()
public function getMacros(): array
{
static $baseMacros = [
return [
...$this->macros,
'getWithHasMore',
'last',
'realCount',
];

return array_merge($this->macros ?? [], $baseMacros);
}

public function getMorphClass()
Expand Down
4 changes: 2 additions & 2 deletions app/Models/ProfileBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProfileBanner extends Model
{
protected $table = 'osu_profile_banners';
protected $primaryKey = 'banner_id';
protected $macros = ['active'];
protected array $macros = ['active'];
public $timestamps = false;

public function user()
Expand All @@ -38,7 +38,7 @@ public function country()
return $this->belongsTo(Country::class, 'country_acronym');
}

public function macroActive()
public function macroActive(): \Closure
{
return function ($query) {
$last = $query->orderBy('banner_id', 'DESC')->first();
Expand Down
8 changes: 4 additions & 4 deletions app/Models/Score/Best/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class Model extends BaseModel implements Traits\ReportableInterface
{
use Traits\Reportable, Traits\WithDbCursorHelper, Traits\WithWeightedPp;

protected $macros = [
protected array $macros = [
'accurateRankCounts',
'forListing',
'userBest',
Expand Down Expand Up @@ -108,7 +108,7 @@ public function getReplayFile(): ?string
return $this->replayFile()?->get();
}

public function macroForListing()
public function macroForListing(): \Closure
{
return function ($query, $limit) {
$limit = clamp($limit ?? 50, 1, $GLOBALS['cfg']['osu']['beatmaps']['max_scores']);
Expand Down Expand Up @@ -170,7 +170,7 @@ public function userRank(?array $params = null): int
]));
}

public function macroUserBest()
public function macroUserBest(): \Closure
{
return function ($query, $limit, $offset = 0, $includes = []) {
$baseResult = (clone $query)
Expand Down Expand Up @@ -206,7 +206,7 @@ public function macroUserBest()
*
* @return array [user_id => [rank => count]]
*/
public function macroAccurateRankCounts()
public function macroAccurateRankCounts(): \Closure
{
return function ($query) {
$scores = (clone $query)
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Store/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Order extends Model
'shipping' => 'float',
];

protected $macros = ['itemsQuantities'];
protected array $macros = ['itemsQuantities'];

protected static function splitTransactionId($value)
{
Expand Down Expand Up @@ -639,7 +639,7 @@ public static function cart($user)
->first();
}

public function macroItemsQuantities()
public function macroItemsQuantities(): \Closure
{
return function ($query) {
$query = clone $query;
Expand Down

0 comments on commit 5dd1476

Please sign in to comment.