Passed
Push — master ( 8b1b0d...c034b2 )
by Anton
02:23
created

PivotedCollectionPromise   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 80
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A matching() 0 5 1
A getPromise() 0 3 1
A getPivot() 0 4 1
A doInitialize() 0 4 1
A getPivotContext() 0 4 1
A __construct() 0 3 1
A setPivot() 0 4 1
A hasPivot() 0 4 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\Relation\Pivoted;
13
14
use Cycle\ORM\Promise\Collection\CollectionPromiseInterface;
15
use Cycle\ORM\Promise\PromiseInterface;
16
use Doctrine\Common\Collections\AbstractLazyCollection;
17
use Doctrine\Common\Collections\Criteria;
18
use Doctrine\Common\Collections\Selectable;
19
20
/**
21
 * Collection at top of pivoted (entity + context entity) promise.
22
 */
23
final class PivotedCollectionPromise extends AbstractLazyCollection implements
24
    CollectionPromiseInterface,
25
    PivotedCollectionInterface,
26
    Selectable
27
{
28
    /** @var PivotedPromise */
29
    protected $promise;
30
31
    /** @var PivotedCollectionInterface */
32
    protected $collection;
33
34
    /**
35
     * @param PivotedPromise $promise
36
     */
37
    public function __construct(PivotedPromise $promise)
38
    {
39
        $this->promise = $promise;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    public function getPromise(): PromiseInterface
46
    {
47
        return $this->promise;
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function hasPivot($element): bool
54
    {
55
        $this->initialize();
56
        return $this->collection->hasPivot($element);
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function getPivot($element)
63
    {
64
        $this->initialize();
65
        return $this->collection->getPivot($element);
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function setPivot($element, $pivot): void
72
    {
73
        $this->initialize();
74
        $this->collection->setPivot($element, $pivot);
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80
    public function getPivotContext(): \SplObjectStorage
81
    {
82
        $this->initialize();
83
        return $this->collection->getPivotContext();
84
    }
85
86
    /**
87
     * @inheritDoc
88
     */
89
    public function matching(Criteria $criteria)
90
    {
91
        $this->initialize();
92
93
        return $this->collection->matching($criteria);
0 ignored issues
show
Bug introduced by
The method matching() does not exist on Cycle\ORM\Relation\Pivot...otedCollectionInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Cycle\ORM\Relation\Pivot...otedCollectionInterface. ( Ignorable by Annotation )

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

93
        return $this->collection->/** @scrutinizer ignore-call */ matching($criteria);
Loading history...
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    protected function doInitialize(): void
100
    {
101
        $storage = $this->promise->__resolve();
102
        $this->collection = new PivotedCollection($storage->getElements(), $storage->getContext());
103
    }
104
}
105