AccountPolicy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 2
A __construct() 0 3 1
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