Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
FilesValidator | |
100.00% |
16 / 16 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
uploaded | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
maxSize | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
mimes | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
ext | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
image | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
maxDim | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
minDim | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
dim | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php declare(strict_types=1); |
2 | /* |
3 | * This file is part of Aplus Framework Validation Library. |
4 | * |
5 | * (c) Natan Felles <natanfelles@gmail.com> |
6 | * |
7 | * For the full copyright and license information, please view the LICENSE |
8 | * file that was distributed with this source code. |
9 | */ |
10 | namespace Framework\Validation\Traits; |
11 | |
12 | /** |
13 | * Trait FilesValidator. |
14 | * |
15 | * @package validation |
16 | */ |
17 | trait FilesValidator |
18 | { |
19 | /** |
20 | * Validates file is uploaded. |
21 | * |
22 | * @return static |
23 | */ |
24 | public function uploaded() : static |
25 | { |
26 | $this->rules[] = 'uploaded'; |
27 | return $this; |
28 | } |
29 | |
30 | /** |
31 | * Validates file size. |
32 | * |
33 | * @param int $kilobytes |
34 | * |
35 | * @return static |
36 | */ |
37 | public function maxSize(int $kilobytes) : static |
38 | { |
39 | $this->rules[] = 'maxSize:' . $kilobytes; |
40 | return $this; |
41 | } |
42 | |
43 | /** |
44 | * Validates file accepted MIME types. |
45 | * |
46 | * @param string ...$allowedTypes |
47 | * |
48 | * @return static |
49 | */ |
50 | public function mimes(string ...$allowedTypes) : static |
51 | { |
52 | $this->rules[] = 'mimes:' . $this->implode($allowedTypes); |
53 | return $this; |
54 | } |
55 | |
56 | /** |
57 | * Validates file accepted extensions. |
58 | * |
59 | * NOTE: For greater security use the {@see FilesValidator::mimes()} method |
60 | * to filter the file type. |
61 | * |
62 | * @param string ...$allowedExtensions |
63 | * |
64 | * @return static |
65 | */ |
66 | public function ext(string ...$allowedExtensions) : static |
67 | { |
68 | $this->rules[] = 'ext:' . $this->implode($allowedExtensions); |
69 | return $this; |
70 | } |
71 | |
72 | /** |
73 | * Validates file is an image. |
74 | * |
75 | * @return static |
76 | */ |
77 | public function image() : static |
78 | { |
79 | $this->rules[] = 'image'; |
80 | return $this; |
81 | } |
82 | |
83 | /** |
84 | * Validates image max dimensions. |
85 | * |
86 | * @param int $width |
87 | * @param int $height |
88 | * |
89 | * @return static |
90 | */ |
91 | public function maxDim(int $width, int $height) : static |
92 | { |
93 | $this->rules[] = 'maxDim:' . $width . ',' . $height; |
94 | return $this; |
95 | } |
96 | |
97 | /** |
98 | * Validates image min dimensions. |
99 | * |
100 | * @param int $width |
101 | * @param int $height |
102 | * |
103 | * @return static |
104 | */ |
105 | public function minDim(int $width, int $height) : static |
106 | { |
107 | $this->rules[] = 'minDim:' . $width . ',' . $height; |
108 | return $this; |
109 | } |
110 | |
111 | /** |
112 | * Validates image dimensions. |
113 | * |
114 | * @param int $width |
115 | * @param int $height |
116 | * |
117 | * @return static |
118 | */ |
119 | public function dim(int $width, int $height) : static |
120 | { |
121 | $this->rules[] = 'dim:' . $width . ',' . $height; |
122 | return $this; |
123 | } |
124 | } |