Passed
Push — master ( 624a9a...4c85b9 )
by Arthur
36:47
created

ScriptAlreadyReviewedGuard   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A condition() 0 7 1
A __construct() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 24.03.19
6
 * Time: 20:00
7
 */
8
9
namespace Modules\Script\Guards;
10
11
12
use Foundation\Guard\Abstracts\Guard;
13
use Modules\Script\Entities\ScriptReview;
14
use Modules\Script\Exceptions\ScriptAlreadyReviewedException;
15
16
class ScriptAlreadyReviewedGuard extends Guard
17
{
18
    protected $exception = ScriptAlreadyReviewedException::class;
19
20
    protected $script;
21
22
    /**
23
     * ScriptAlreadyReviewedGuard constructor.
24
     * @param $script
25
     */
26 2
    public function __construct($script)
27
    {
28 2
        $this->script = $script;
29 2
    }
30
31 2
    public function condition(): bool
32
    {
33 2
        return $this->script->reviews()
34 2
            ->withTrashed()
35 2
            ->where(ScriptReview::REVIEWER_ID, get_authenticated_user_id())
36 2
            ->get()
37 2
            ->isNotEmpty();
38
    }
39
40
41
}
42