Passed
Push — analysis-z4nkaD ( 2af593 )
by Philippe
11:48 queued 27s
created

Nomadic::nomadicCan()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 8
rs 9.6111
cc 5
nc 3
nop 1
1
<?php
2
3
namespace Thinktomorrow\Chief\Management;
4
5
use Thinktomorrow\Chief\Management\Exceptions\NotAllowedManagerRoute;
6
7
trait Nomadic
8
{
9
    public function nomadicCan($verb)
10
    {
11
        if ($this->indexCollection()->count() > 0 && in_array($verb, ['create', 'store'])) {
0 ignored issues
show
Bug introduced by
It seems like indexCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

11
        if ($this->/** @scrutinizer ignore-call */ indexCollection()->count() > 0 && in_array($verb, ['create', 'store'])) {
Loading history...
12
            throw NotAllowedManagerRoute::create($this);
0 ignored issues
show
Bug introduced by
$this of type Thinktomorrow\Chief\Management\Nomadic is incompatible with the type Thinktomorrow\Chief\Management\Manager expected by parameter $manager of Thinktomorrow\Chief\Mana...dManagerRoute::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

12
            throw NotAllowedManagerRoute::create(/** @scrutinizer ignore-type */ $this);
Loading history...
13
        }
14
15
        if (! auth()->guard('chief')->user()->hasRole('developer') && in_array($verb, ['create', 'store', 'delete'])) {
0 ignored issues
show
Bug introduced by
The method hasRole() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        if (! auth()->guard('chief')->user()->/** @scrutinizer ignore-call */ hasRole('developer') && in_array($verb, ['create', 'store', 'delete'])) {
Loading history...
16
            throw NotAllowedManagerRoute::notAllowedVerb($verb, $this);
0 ignored issues
show
Bug introduced by
$this of type Thinktomorrow\Chief\Management\Nomadic is incompatible with the type Thinktomorrow\Chief\Management\Manager expected by parameter $manager of Thinktomorrow\Chief\Mana...Route::notAllowedVerb(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
            throw NotAllowedManagerRoute::notAllowedVerb($verb, /** @scrutinizer ignore-type */ $this);
Loading history...
17
        }
18
    }
19
}
20