NoObjectExistsFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModule\Validator\Service;
6
7
use DoctrineModule\Validator\NoObjectExists;
8
use Interop\Container\ContainerInterface;
9
10
/**
11
 * Factory for creating NoObjectExists instances
12
 *
13
 * @link    http://www.doctrine-project.org/
14
 */
15
class NoObjectExistsFactory extends AbstractValidatorFactory
16
{
17
    /** @var string */
18
    protected $validatorClass = NoObjectExists::class;
19
20
    /**
21
     * {@inheritDoc}
22
     */
23 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
24
    {
25 2
        $container = $this->container($container);
26
27 2
        $repository = $this->getRepository($container, $options);
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 23 can also be of type array; however, DoctrineModule\Validator...actory::getRepository() does only seem to accept array<integer,*>|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
28
29 2
        return new NoObjectExists($this->merge($options, [
0 ignored issues
show
Documentation introduced by
$options is of type null|array, but the function expects a array<integer,*>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30 2
            'object_repository' => $repository,
31 2
            'fields'            => $this->getFields($options),
0 ignored issues
show
Documentation introduced by
$options is of type null|array, but the function expects a array<integer,*>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
        ]));
33
    }
34
}
35