AccountPolicy::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 12.10.18
6
 * Time: 01:25.
7
 */
8
9
namespace Modules\Account\Policies;
10
11
use Foundation\Exceptions\Exception;
12
use Foundation\Policies\OwnershipPolicy;
13
use Modules\Account\Contracts\AccountServiceContract;
14
use Modules\User\Entities\User;
15
16
class AccountPolicy extends OwnershipPolicy
17
{
18
    protected $service;
19
20
    /**
21
     * AccountPolicy constructor.
22
     *
23
     * @param $service
24
     */
25
    public function __construct(AccountServiceContract $service)
26
    {
27
        $this->service = $service;
28
    }
29
30
    public function create(User $user): bool
31
    {
32
        $AccountCount = $this->service->getByUserId($user->id)->count();
33
34
        $maxAccountCount = 20;
35
36
        if ($AccountCount > $maxAccountCount) {
37
            throw new Exception('You Cannot create more than 20 Accounts. 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