Completed
Push — master ( e1ce3b...f144d1 )
by Anton
14s queued 12s
created

CollectionPromise   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A doInitialize() 0 3 1
A getPromise() 0 3 1
A matching() 0 5 1
1
<?php
2
3
/**
4
 * Cycle DataMapper ORM
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\ORM\Promise\Collection;
13
14
use Cycle\ORM\Promise\PromiseInterface;
15
use Doctrine\Common\Collections\AbstractLazyCollection;
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Criteria;
18
use Doctrine\Common\Collections\Selectable;
19
20
/**
21
 * LazyLoading collection build at top of data promise.
22
 */
23
class CollectionPromise extends AbstractLazyCollection implements CollectionPromiseInterface, Selectable
24
{
25
    /** @var PromiseInterface */
26
    protected $promise;
27
28
    /**
29
     * @param PromiseInterface $promise
30
     */
31
    public function __construct(PromiseInterface $promise)
32
    {
33
        $this->promise = $promise;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getPromise(): PromiseInterface
40
    {
41
        return $this->promise;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    protected function doInitialize(): void
48
    {
49
        $this->collection = new ArrayCollection($this->promise->__resolve());
0 ignored issues
show
Bug introduced by
It seems like $this->promise->__resolve() can also be of type null; however, parameter $elements of Doctrine\Common\Collecti...llection::__construct() does only seem to accept array, 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

49
        $this->collection = new ArrayCollection(/** @scrutinizer ignore-type */ $this->promise->__resolve());
Loading history...
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function matching(Criteria $criteria)
56
    {
57
        $this->initialize();
58
59
        return $this->collection->matching($criteria);
0 ignored issues
show
Bug introduced by
The method matching() does not exist on Doctrine\Common\Collections\Collection. It seems like you code against a sub-type of Doctrine\Common\Collections\Collection such as Doctrine\Common\Collections\ArrayCollection or Cycle\ORM\Promise\Collection\CollectionPromise or Cycle\ORM\Relation\Pivoted\PivotedCollection or Cycle\ORM\Promise\Collection\CollectionPromise. ( Ignorable by Annotation )

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

59
        return $this->collection->/** @scrutinizer ignore-call */ matching($criteria);
Loading history...
60
    }
61
}
62