AccountRepository::findLastUpdatedByUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Repositories;
6
7
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
8
use Illuminate\Database\Eloquent\Builder;
9
use Minepic\Models\Account;
10
11
class AccountRepository
12
{
13
    /**
14
     * @return Builder<Account>
15
     */
16
    public function filterQuery(array $filters = []): Builder
17
    {
18
        $query = Account::query();
19
        if (\array_key_exists('term', $filters)) {
20
            $query->where('username', 'LIKE', '%'.$filters['term'].'%');
21
        }
22
23
        return $query;
24
    }
25
26
    /**
27
     * Last updated username.
28
     */
29
    public function findLastUpdatedByUsername(string $uuid): ?Account
30
    {
31
        return Account::query()
32
            ->select()
33
            ->whereUsername($uuid)
34
            ->orderBy('updated_at', 'desc')
35
            ->first();
36
    }
37
38
    /**
39
     * @return LengthAwarePaginator<Account>
40
     */
41
    public function filterPaginate(
42
        array $filters,
43
        ?int $perPage = null,
44
        array $columns = ['*'],
45
        string $pageName = 'page',
46
        ?int $page = null
47
    ): LengthAwarePaginator {
48
        return $this->filterQuery($filters)
49
            ->paginate($perPage, $columns, $pageName, $page);
50
    }
51
}
52