Passed
Push — master ( 10a915...0d23d6 )
by Mattia
08:28 queued 11s
created

AccountStatsRepository::model()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Repositories;
6
7
use App\Models\AccountStats;
8
use Czim\Repository\BaseRepository;
9
10
/**
11
 * Class AccountStatsRepository.
12
 */
13
class AccountStatsRepository extends BaseRepository
14
{
15
    public function model(): string
16
    {
17
        return AccountStats::class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\AccountStats::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 User UUID
24
     * @param array $columns Which columns should be loaded
25
     * @return \App\Models\AccountStats Statistics related to given UUID
26
     */
27
    public function findByUuid(string $uuid, $columns = ['*']): AccountStats
28
    {
29
        return $this->findBy('uuid', $uuid, $columns);
30
    }
31
32
    /**
33
     * Increment request counter.
34
     * @param string $uuid User UUID
35
     */
36
    public function incrementRequestCounter(string $uuid = ''): void
37
    {
38
        $this->query()
39
            ->where('uuid', $uuid)
40
            ->update([
41
                'count_request' => app('db')->raw('count_request + 1'),
42
                'time_request' => \time(),
43
            ]);
44
    }
45
46
    /**
47
     * Increment search counter.
48
     * @param string $uuid User UUID
49
     */
50
    public function incrementSearchCounter(string $uuid = ''): void
51
    {
52
        $this->query()
53
            ->where('uuid', $uuid)
54
            ->update([
55
                'count_search' => app('db')->raw('count_search + 1'),
56
                'time_search' => \time(),
57
            ]);
58
    }
59
}
60