Passed
Push — task/application-handle-step-s... ( 5a9035...2b5b8c )
by Yonathan
04:05
created

IncludesAllRule::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class IncludesAllRule implements Rule
9
{
10
    /**
11
     *  @var mixed $collection
12
     */
13
    protected $collection;
14
15
    /**
16
     * Create a new rule instance.
17
     *
18
     * @param  mixed $collection Array to validate against.
19
     * @return void
20
     */
21
    public function __construct($collection)
22
    {
23
        $this->collection = $collection;
24
    }
25
26
    /**
27
     * This check passes if $value has at least one of
28
     * every element in $this->collection.
29
     * @param  mixed $attribute
30
     * @param  mixed $value
31
     * @return boolean
32
     */
33
    public function passes($attribute, $value)
34
    {
35
        // Diff should return an empty array if all elements in
36
        // $this->collection are present in $value.
37
        return empty(array_diff($this->collection, $value));
38
    }
39
40
    public function message()
41
    {
42
        return Lang::get(
43
            'validation.includes_all'
44
        );
45
    }
46
}
47