ScriptAlreadyReviewedGuard::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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