Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
4 / 4
Base64
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 check
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
1<?php
2
3namespace Qmp\Laravel\ValidationRules\Rules;
4
5class Base64 extends Rule
6{
7        /**
8     * Undocumented variable
9     *
10     * @var string
11     */
12    protected $message = 'The :attribute must have an encoded base64 value';
13
14    /**
15     * Undocumented variable
16     *
17     * @var string
18     */
19    protected $pattern = "/^data:[a-z]+\/[a-z]{2,};base64,[0-9a-zA-Z\/+=]+/";
20
21    /**
22     * Undocumented function
23     *
24     * @param string $attribute
25     * @param mixed $value
26     * @param array $parameters
27     * @return bool
28     */
29    public function check(string $attribute, $value, array $parameters): bool
30    {
31        if (!is_string($value)) {
32            $this->setError('The :attribute is not a string');
33            return false;
34        }
35        return preg_match($this->pattern, $value);
36    }
37}