Passed
Pull Request — master (#17)
by ARCANEDEV
05:21
created

MediaItemExistsRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php namespace Arcanesoft\Media\Rules;
2
3
use Arcanesoft\Media\MediaManager;
4
use Illuminate\Contracts\Validation\Rule;
5
6
/**
7
 * Class     MediaItemExistsRule
8
 *
9
 * @package  Arcanesoft\Media\Rules
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class MediaItemExistsRule implements Rule
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /** @var  \Arcanesoft\Media\MediaManager */
20
    protected $manager;
21
22
    /* -----------------------------------------------------------------
23
     |  Constructor
24
     | -----------------------------------------------------------------
25
     */
26
27
    public function __construct(MediaManager $manager)
28
    {
29
        $this->manager = $manager;
30
    }
31
32
    /* -----------------------------------------------------------------
33
     |  Main Methods
34
     | -----------------------------------------------------------------
35
     */
36
37
    /**
38
     * Determine if the validation rule passes.
39
     *
40
     * @param  string  $attribute
41
     * @param  mixed   $value
42
     *
43
     * @return bool
44
     */
45
    public function passes($attribute, $value)
46
    {
47
        return $this->manager->exists($value);
48
    }
49
50
    /**
51
     * Get the validation error message.
52
     *
53
     * @return string|array
54
     */
55
    public function message()
56
    {
57
        return 'The attribute :attribute does not exists';
58
    }
59
}
60