IsBase64Type::passes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Owowagency\LaravelMedia\Rules;
4
5
use Illuminate\Support\Arr;
6
use Owowagency\LaravelMedia\Rules\Concerns\ValidatesBase64;
7
8
class IsBase64Type extends IsBase64
9
{
10
    use ValidatesBase64;
11
12
    /**
13
     * The base64 types to check in the test.
14
     *
15
     * @var array
16
     */
17
    private $types;
18
19
    /**
20
     * Create a notification instance.
21
     *
22
     * @param  string|array  $type
23
     * @return void
24
     */
25
    public function __construct($types)
26
    {
27
        $this->types = Arr::wrap($types);
28
    }
29
30
    /**
31
     * Determine if the validation rule passes.
32
     *
33
     * @param  string  $attribute
34
     * @param  mixed  $value
35
     * @return bool
36
     */
37
    public function passes($attribute, $value)
38
    {
39
        if (! $this->isBase64($value)) {
40
            return false;
41
        }
42
43
        return in_array($this->getMimeType($value), $this->types);
44
    }
45
46
    /**
47
     * Get the validation error message.
48
     *
49
     * @return string
50
     */
51
    public function message(): string
52
    {
53
        return trans('validation.custom.is_base_64_type', ['type' => implode(',', $this->types)]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('validation...de(',', $this->types))) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
54
    }
55
}
56