1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * This file is part of Dimtrovich/Validation. |
||||
5 | * |
||||
6 | * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]> |
||||
7 | * |
||||
8 | * For the full copyright and license information, please view |
||||
9 | * the LICENSE file that was distributed with this source code. |
||||
10 | */ |
||||
11 | |||||
12 | namespace Dimtrovich\Validation\Rules; |
||||
13 | |||||
14 | use Dimtrovich\Validation\Traits\FileTrait; |
||||
15 | use Rakit\Validation\Rule; |
||||
16 | use Rakit\Validation\Rules\Mimes as RulesMimes; |
||||
17 | |||||
18 | class Mimes extends AbstractRule |
||||
19 | { |
||||
20 | use FileTrait; |
||||
21 | |||||
22 | protected array $parameters = []; |
||||
23 | |||||
24 | /** |
||||
25 | * {@inheritDoc} |
||||
26 | */ |
||||
27 | public function fillParameters(array $params): Rule |
||||
28 | { |
||||
29 | 4 | return $this->fillAllowedValuesParameters($params); |
|||
30 | } |
||||
31 | |||||
32 | /** |
||||
33 | * {@inheritDoc} |
||||
34 | */ |
||||
35 | public function check($value): bool |
||||
36 | { |
||||
37 | 4 | $this->requireParameters(['allowed_values']); |
|||
38 | 4 | $this->setAllowedValues($this->parameters = $this->parameter('allowed_values')); |
|||
39 | |||||
40 | if (! $this->isValidFileInstance($value)) { |
||||
41 | 4 | $rule = new RulesMimes(); |
|||
42 | $rule->setAttribute($this->getAttribute()); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
43 | $rule->setValidation($this->validation); |
||||
0 ignored issues
–
show
It seems like
$this->validation can also be of type null ; however, parameter $validation of Rakit\Validation\Rule::setValidation() does only seem to accept Rakit\Validation\Validation , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
44 | $rule->setKey($this->getKey()); |
||||
45 | $rule->setParameters($this->getParameters()); |
||||
46 | $rule->setMessage($this->getMessage()); |
||||
47 | $rule->allowTypes($this->parameters); |
||||
48 | |||||
49 | return $rule->check($value); |
||||
50 | } |
||||
51 | |||||
52 | if ($this->shouldBlockPhpUpload($value, $this->parameters)) { |
||||
53 | return false; |
||||
54 | } |
||||
55 | |||||
56 | 4 | return $value->getPath() !== '' && in_array($value->guessExtension(), $this->parameters, true); |
|||
57 | } |
||||
58 | } |
||||
59 |