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

MediaItemExistsRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A passes() 0 3 1
A message() 0 3 1
A __construct() 0 3 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