Issues (88)

src/Rules/PresentWithAll.php (3 issues)

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 Rakit\Validation\Rule;
15
16
class PresentWithAll extends AbstractRule
17
{
18
    /**
19
     * @var bool
20
     */
21
    protected $implicit = true;
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function fillParameters(array $params): Rule
27
    {
28
        $this->params['fields'] = $params;
29
30
        return $this;
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function check($value): bool
37
    {
38
        $this->requireParameters(['fields']);
39
40
        $fields = $this->parameter('fields');
41
42
        $this->setParameterTextValues($fields, 'values');
43
44
        foreach ($fields as $field) {
45
            if (! $this->validation->hasValue($field)) {
0 ignored issues
show
The method hasValue() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            if (! $this->validation->/** @scrutinizer ignore-call */ hasValue($field)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
                return true;
47
            }
48
        }
49
50
        $presentValidator = $this->getRuleValidator('present');
51
52
        $presentValidator->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 ignore-type  annotation

52
        $presentValidator->setValidation(/** @scrutinizer ignore-type */ $this->validation);
Loading history...
53
        $presentValidator->setAttribute($this->attribute);
0 ignored issues
show
It seems like $this->attribute can also be of type null; however, parameter $attribute of Rakit\Validation\Rule::setAttribute() does only seem to accept Rakit\Validation\Attribute, 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 ignore-type  annotation

53
        $presentValidator->setAttribute(/** @scrutinizer ignore-type */ $this->attribute);
Loading history...
54
55
        return $presentValidator->check($value);
56
    }
57
}
58