Passed
Push — master ( e43bfe...032fef )
by Mattia
03:24
created

AccountStatsRepository::createEmptyStatsForUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 8
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
     * @param string $uuid
22
     * @return \Illuminate\Database\Eloquent\Model|AccountStats|null
23
     */
24
    public function createEmptyStatsForUuid(string $uuid): ?AccountStats
25
    {
26
        return $this->create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->create(arr..., 'time_request' => 0)) returns the type Illuminate\Database\Eloquent\Model which includes types incompatible with the type-hinted return App\Models\AccountStats|null.
Loading history...
27
            'uuid' => $uuid,
28
            'count_search' => 0,
29
            'count_request' => 0,
30
            'time_search' => 0,
31
            'time_request' => 0,
32
        ]);
33
    }
34
35
    /**
36
     * Increment request counter.
37
     *
38
     * @param string $uuid User UUID
39
     */
40
    public function incrementRequestCounter(string $uuid = ''): void
41
    {
42
        $this->query()
43
            ->where('uuid', $uuid)
44
            ->update([
45
                'count_request' => app('db')->raw('count_request + 1'),
46
                'time_request' => \time(),
47
            ]);
48
    }
49
}
50