Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

SchedulePolicy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 8 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 12.10.18
6
 * Time: 01:25.
7
 */
8
9
namespace Modules\Schedule\Policies;
10
11
use Foundation\Exceptions\Exception;
12
use Foundation\Policies\OwnershipPolicy;
13
use Modules\Schedule\Contracts\ScheduleServiceContract;
14
use Modules\User\Entities\User;
15
16
class SchedulePolicy extends OwnershipPolicy
17
{
18
    protected $service;
19
20
    /**
21
     * SchedulePolicy constructor.
22
     *
23
     * @param $service
24
     */
25
    public function __construct(ScheduleServiceContract $service)
26
    {
27
        $this->service = $service;
28
    }
29
30
    public function create(User $user): bool
31
    {
32
        $ScheduleCount = $this->service->getByUserId($user->id)->count();
33
34
        $maxScheduleCount = 20;
35
36
        if ($ScheduleCount > $maxScheduleCount) {
37
            throw new Exception('You Cannot create more than 20 Schedules. Delete one first', 401);
38
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 36 is false. This is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
    }
40
}
41