FactoryQueue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A add() 0 4 1
A insert() 0 4 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Hydrator package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\PhpApi\Hydrator\Processors\Factory;
10
11
/**
12
 * @author John Kleijn <[email protected]>
13
 */
14
class FactoryQueue extends \SplPriorityQueue
15
{
16
    /**
17
     * @var int
18
     */
19
    protected $serial = PHP_INT_MAX;
20
21
    /**
22
     * PriorityQueue constructor.
23
     * @param Factory[] ...$factories
24
     */
25
    public function __construct(Factory ...$factories)
26
    {
27
        foreach ($factories as $factory) {
28
            $this->add($factory);
0 ignored issues
show
Documentation introduced by
$factory is of type array<integer,object<Kle...ssors\Factory\Factory>>, but the function expects a object<KleijnWeb\PhpApi\...essors\Factory\Factory>.

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...
29
        }
30
    }
31
32
    /**
33
     * @param Factory $factory
34
     */
35
    public function add(Factory $factory)
36
    {
37
        $this->insert($factory, $factory->getPriority());
38
    }
39
40
    /**
41
     * @param mixed $value
42
     * @param mixed $priority
43
     */
44
    public function insert($value, $priority)
45
    {
46
        parent::insert($value, [$priority, $this->serial--]);
47
    }
48
}
49