Passed
Push — master ( 2c144a...cc2b65 )
by Christian
03:20
created

ExistsAndDeletePermission   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 16
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Permissions\Features;
4
5
use Omatech\Mage\Core\Domains\Permissions\Permission;
6
use Omatech\Mage\Core\Domains\Permissions\Jobs\DeletePermission;
7
use Omatech\Mage\Core\Domains\Permissions\Jobs\ExistsPermission;
8
use Omatech\Mage\Core\Domains\Permissions\Jobs\AttachedPermission;
9
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionIsAttachedException;
10
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionDoesNotExistsException;
11
12
class ExistsAndDeletePermission
13
{
14
    private $exists;
15
    private $attached;
16
    private $delete;
17
18
    /**
19
     * ExistsAndDeletePermission constructor.
20
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
21
     */
22 3
    public function __construct()
23
    {
24 3
        $this->exists = app()->make(ExistsPermission::class);
25 3
        $this->attached = app()->make(AttachedPermission::class);
26 3
        $this->delete = app()->make(DeletePermission::class);
27 3
    }
28
29
    /**
30
     * @param Permission $permission
31
     * @return bool
32
     * @throws PermissionDoesNotExistsException
33
     * @throws PermissionIsAttachedException
34
     */
35 3 View Code Duplication
    public function make(Permission $permission): bool
36
    {
37 3
        $exists = $this->exists->make($permission);
38
39 3
        if ($exists === false) {
40 1
            throw new PermissionDoesNotExistsException;
41
        }
42
43 3
        $attached = $this->attached->make($permission);
44
45 3
        if ($attached === true) {
46 1
            throw new PermissionIsAttachedException;
47
        }
48
49 2
        return $this->delete->make($permission);
50
    }
51
}
52