Completed
Push — master ( 5decb7...aee104 )
by Thibaud
14:37 queued 11:26
created

BasketElement::getNote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Entity;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
16
class BasketElement
17
{
18
    /**
19
     * @param \stdClass[] $values
20
     * @return BasketElement[]
21
     */
22 1
    public static function fromList(array $values)
23
    {
24 1
        $elements = array();
25
26 1
        foreach ($values as $value) {
27 1
            $elements[$value->basket_element_id] = self::fromValue($value);
28 1
        }
29
30 1
        return $elements;
31
    }
32
33
    /**
34
     * @param \stdClass $value
35
     * @return BasketElement
36
     */
37 1
    public static function fromValue(\stdClass $value)
38
    {
39 1
        return new self($value);
40
    }
41
42
    /**
43
     * @var \stdClass
44
     */
45
    protected $source;
46
47
    /**
48
     * @var Record
49
     */
50
    protected $record;
51
52
    /**
53
     * @var ArrayCollection|BasketValidationChoice[]
54
     */
55
    protected $validationChoices;
56
57
    /**
58
     * @param \stdClass $source
59
     */
60 1
    public function __construct(\stdClass $source)
61
    {
62 1
        $this->source = $source;
63 1
    }
64
65
    /**
66
     * @return \stdClass
67
     */
68
    public function getRawData()
69
    {
70
        return $this->source;
71
    }
72
73
    /**
74
     * The id of the element
75
     *
76
     * @return integer
77
     */
78 1
    public function getId()
79
    {
80 1
        return (int) $this->source->basket_element_id;
81
    }
82
83
    /**
84
     * Position of the element in the basket
85
     *
86
     * @return integer
87
     */
88 1
    public function getOrder()
89
    {
90 1
        return (int) $this->source->order;
91
    }
92
93
    /**
94
     * Tell whether the basket item is a validation item
95
     *
96
     * @return bool
97
     */
98 1
    public function isValidationItem()
99
    {
100 1
        return $this->source->validation_item;
101
    }
102
103
    /**
104
     * Get the record associated to the basket item
105
     *
106
     * @return Record
107
     */
108 1
    public function getRecord()
109
    {
110 1
        return $this->record ?: $this->record = Record::fromValue($this->source->record);
111
    }
112
113
    /**
114
     * Retrieve the choice of all participants that concern the basket element
115
     * in a collection PhraseanetSDK\Entity\BasketValidationChoice object
116
     *
117
     * @return ArrayCollection
118
     */
119 1
    public function getValidationChoices()
120
    {
121 1
        if (! isset($this->source->validation_choices)) {
122
            $this->validationChoices = new ArrayCollection();
123
        }
124
125 1
        return $this->validationChoices ?: $this->validationChoices = new ArrayCollection(
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->validationChoices...>validation_choices))); of type Doctrine\Common\Collecti...asketValidationChoice[] adds the type PhraseanetSDK\Entity\BasketValidationChoice[] to the return on line 125 which is incompatible with the return type documented by PhraseanetSDK\Entity\Bas...t::getValidationChoices of type Doctrine\Common\Collections\ArrayCollection.
Loading history...
126 1
            BasketValidationChoice::fromList($this->source->validation_choices)
127 1
        );
128
    }
129
130
    /**
131
     * Get the annotation about the validation of the current authenticated user
132
     *
133
     * @return int
134
     */
135 1
    public function getNote()
136
    {
137 1
        return (int) $this->source->note;
138
    }
139
140
    /**
141
     * Get the agreement of the currently authenticated user
142
     *
143
     * - null : no response yet
144
     * - true : accepted
145
     * - false: rejected
146
     *
147
     * @return null|boolean
148
     */
149 1
    public function getAgreement()
150
    {
151 1
        return $this->source->agreement;
152
    }
153
}
154