Passed
Push — dev ( c55022...971015 )
by Mattia
05:44
created

AccountRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findByUsername() 0 3 1
A findLastUpdatedByUsername() 0 7 1
A findByUuid() 0 3 1
A model() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Repositories;
6
7
use App\Models\Account;
8
use Czim\Repository\BaseRepository;
9
10
/**
11
 * Class AccountRepository.
12
 */
13
class AccountRepository extends BaseRepository
14
{
15
    public function model(): string
16
    {
17
        return Account::class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Account::class returns the type string which is incompatible with the return type mandated by Czim\Repository\Contract...itoryInterface::model() of Illuminate\Database\Eloquent\Model.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
18
    }
19
20
    /**
21
     * Find account using UUID
22
     *
23
     * @param string $uuid
24
     * @param array $columns
25
     * @return Account
26
     */
27
    public function findByUuid(string $uuid, $columns = ['*']): Account
28
    {
29
        return $this->findBy('uuid', $uuid, $columns);
30
    }
31
32
    /**
33
     * @param string $uuid
34
     * @param array $columns
35
     * @return Account
36
     */
37
    public function findByUsername(string $uuid, $columns = ['*']): Account
38
    {
39
        return $this->findBy('username', $uuid, $columns);
40
    }
41
42
    /**
43
     * Last updated username.
44
     *
45
     * @param string $uuid
46
     * @param array $columns
47
     *
48
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
49
     */
50
    public function findLastUpdatedByUsername(string $uuid, $columns = ['*'])
51
    {
52
        return $this->query()
53
            ->select($columns)
54
            ->where('username', '=', $uuid)
55
            ->orderBy('updated_at', 'desc')
56
            ->first();
57
    }
58
}
59