Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
15 / 15 |
CheckSiteDetailsOtherFilesRule | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
15 / 15 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
passes | |
100.00% |
1 / 1 |
6 | |
100.00% |
12 / 12 |
|||
message | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\SiteGeneratorDetail\Rules; |
4 | |
5 | use Illuminate\Contracts\Validation\Rule; |
6 | use Illuminate\Support\Facades\Validator; |
7 | use Qmp\Laravel\ValidationRules\Rules\Base64; |
8 | |
9 | |
10 | class CheckSiteDetailsOtherFilesRule implements Rule |
11 | { |
12 | private $errors; |
13 | |
14 | /** |
15 | * Create a new rule instance. |
16 | * |
17 | * @return void |
18 | */ |
19 | public function __construct() |
20 | { |
21 | $this->errors = []; |
22 | } |
23 | |
24 | /** |
25 | * Determine if the validation rule passes. |
26 | * |
27 | * @param string $attribute |
28 | * @param mixed $value |
29 | * @return bool |
30 | */ |
31 | public function passes($attribute, $value) |
32 | { |
33 | if($value) { |
34 | if(!isset($value['name']) || !isset($value['dataURL'])) { |
35 | return false; |
36 | } |
37 | |
38 | //if is not filename in dataURL |
39 | if(!preg_match('/\/[a-zA-Z_-]+\/[0-9a-z-A-Z_-]+.[a-z]{3}/', $value['dataURL'])) |
40 | { |
41 | $validator = Validator::make( |
42 | ['dataURL' => $value['dataURL']], |
43 | ['dataURL' => new Base64()] |
44 | ); |
45 | |
46 | if(!$validator->passes()) { |
47 | $errors = $validator->errors(); |
48 | $this->errors = array_merge($this->errors, $errors->all()); |
49 | |
50 | return false; |
51 | } |
52 | } |
53 | } |
54 | |
55 | return true; |
56 | } |
57 | |
58 | /** |
59 | * Get the validation error message. |
60 | * |
61 | * @return string |
62 | */ |
63 | public function message() |
64 | { |
65 | return 'The :attribute is not valid object. ' . implode(' ', $this->errors); |
66 | } |
67 | } |