ScriptAlreadyReviewedGuard   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 37
ccs 0
cts 11
cp 0
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
use Larapie\Guard\Guard;
12
use Modules\Script\Entities\Script;
13
use Modules\Script\Entities\ScriptReview;
14
use Modules\Script\Exceptions\ScriptAlreadyReviewedException;
15
16
/**
17
 * Class ScriptAlreadyReviewedGuard
18
 * @package Modules\Script\Guards
19
 */
20
class ScriptAlreadyReviewedGuard extends Guard
21
{
22
23
    /**
24
     * The exception that will be thrown when the condition is met
25
     *
26
     * @var string
27
     */
28
    protected $exception = ScriptAlreadyReviewedException::class;
29
30
31
    /**
32
     * @var Script
33
     */
34
    protected $script;
35
36
    /**
37
     * ScriptAlreadyReviewedGuard constructor.
38
     * @param $script
39
     */
40
    public function __construct(Script $script)
41
    {
42
        $this->script = $script;
43
    }
44
45
    /**
46
     * The condition that needs to be satisfied in order to throw the exception.
47
     *
48
     * @return bool
49
     */
50
    public function condition(): bool
51
    {
52
        return $this->script->reviews()
53
            ->withTrashed()
54
            ->where(ScriptReview::REVIEWER_ID, get_authenticated_user_id())
55
            ->get()
56
            ->isNotEmpty();
57
    }
58
}
59