BufferedCollect   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getObjects() 0 3 1
A getAssociationPath() 0 3 1
A setAssociatedEntities() 0 7 2
A getAssociatedEntities() 0 7 2
1
<?php
2
3
namespace Xsolve\Associate\BufferedCollector;
4
5
use Xsolve\Associate\AssociationPath\AssociationPath;
6
7
class BufferedCollect
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $objects;
13
14
    /**
15
     * @var AssociationPath
16
     */
17
    protected $associationPath;
18
19
    /**
20
     * @var array|null
21
     */
22
    protected $associatedEntities;
23
24
    /**
25
     * @param array     $objects
26
     * @param string[]  $associationNames
27
     */
28
    public function __construct(
29
        array $objects,
30
        array $associationNames
31
    ) {
32
        $this->objects = $objects;
33
        $this->associationPath = new AssociationPath($associationNames);
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getObjects(): array
40
    {
41
        return $this->objects;
42
    }
43
44
    /**
45
     * @return AssociationPath
46
     */
47
    public function getAssociationPath(): AssociationPath
48
    {
49
        return $this->associationPath;
50
    }
51
52
    /**
53
     * @param array $associatedEntities
54
     *
55
     * @throws \Exception
56
     */
57
    public function setAssociatedEntities(array $associatedEntities)
58
    {
59
        if (!is_null($this->associatedEntities)) {
60
            throw new \Exception('Associated entities were already set.');
61
        }
62
63
        $this->associatedEntities = $associatedEntities;
64
    }
65
66
    /**
67
     * @return array
68
     *
69
     * @throws \Exception
70
     */
71
    public function getAssociatedEntities(): array
72
    {
73
        if (is_null($this->associatedEntities)) {
74
            throw new \Exception('Associated entities were not set.');
75
        }
76
77
        return $this->associatedEntities;
78
    }
79
}
80