Passed
Push — master ( d740d1...5e58be )
by Michael
02:27
created

IncludedObjectsContainer::addIncludedIterator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Bundle\JsonApiBundle\Response\Behaviour;
5
6
/**
7
 * Behaviour of a container of included objects
8
 *
9
 * @package Mikemirten\Bundle\JsonApiBundle\Response\Behaviour
10
 */
11
trait IncludedObjectsContainer
12
{
13
    /**
14
     * Objects supposed to be included to document
15
     *
16
     * @var array
17
     */
18
    protected $includedObjects = [];
19
20
    /**
21
     * Add included object to document
22
     *
23
     * @param mixed $object
24
     */
25 1
    public function addIncludedObject($object)
26
    {
27 1
        $this->includedObjects[] = $object;
28 1
    }
29
30
    /**
31
     * Add an iterator contains objects should be included
32
     *
33
     * @param \Traversable $iterator
34
     */
35 1
    public function addIncludedIterator(\Traversable $iterator)
36
    {
37 1
        foreach ($iterator as $object)
38
        {
39 1
            $this->includedObjects[] = $object;
40
        }
41 1
    }
42
43
    /**
44
     * Get objects included to document
45
     *
46
     * @return array
47
     */
48 3
    public function getIncludedObjects(): array
49
    {
50 3
        return $this->includedObjects;
51
    }
52
}