Completed
Pull Request — master (#141)
by
unknown
12:54
created

CustomerOrder::getCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Traits\TimestampableTrait;
6
use Doctrine\Common\Annotations\Annotation\Enum;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use JMS\Serializer\Annotation\ExclusionPolicy;
10
use JMS\Serializer\Annotation\Expose;
11
use Ramsey\Uuid\Uuid;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
/**
15
 * @ORM\Table(name="customer_order")
16
 * @ORM\Entity(repositoryClass="AppBundle\Repository\CustomerOrderRepository")
17
 * @ExclusionPolicy("all")
18
 */
19
class CustomerOrder
20
{
21
    use TimestampableTrait;
22
23
    const STATUS_OPENED   = 'opened';
24
    const STATUS_CLOSED   = 'closed';
25
    const STATUS_PENDING  = 'pending';
26
    const STATUS_PAID     = 'paid';
27
    const STATUS_REJECTED = 'rejected';
28
29
    /**
30
     * @var Uuid
31
     *
32
     * @ORM\Column(name="id", type="uuid_binary")
33
     * @ORM\Id
34
     * @ORM\GeneratedValue(strategy="UUID")
35
     */
36
    private $id;
37
38
    /**
39
     * @var ArrayCollection|Ticket[]
40
     *
41
     * @ORM\OneToMany(
42
     *     targetEntity="AppBundle\Entity\Ticket",
43
     *     mappedBy="customerOrder",
44
     *     cascade={"persist", "remove"}
45
     * )
46
     */
47
    protected $tickets;
48
49
    /**
50
     * @var Enum
51
     * @Assert\Choice(callback="getStatuses")
52
     * @ORM\Column(
53
     *     name="status",
54
     *     type="string",
55
     *     columnDefinition="enum('free', 'booked', 'ordered', 'opened', 'closed')"
56
     * )
57
     * @Expose()
58
     */
59
    protected $status;
60
61
    /**
62
     * @var Customer
63
     *
64
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Customer")
65
     */
66
    protected $customer;
67
68
    /**
69
     * CustomerOrder constructor.
70
     */
71
    public function __construct(Customer $customer)
72
    {
73
        $this->status = self::STATUS_OPENED;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::STATUS_OPENED of type string is incompatible with the declared type object<Doctrine\Common\A...ations\Annotation\Enum> of property $status.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
        $this->tickets = new ArrayCollection();
75
        $this->customer = $customer;
76
    }
77
78
    /**
79
     * @return Uuid
80
     */
81
    public function getId()
82
    {
83
        return $this->id;
84
    }
85
86
    /**
87
     * @return Ticket[]|ArrayCollection
88
     */
89
    public function getTickets()
90
    {
91
        return $this->tickets;
92
    }
93
94
    /**
95
     * @param Ticket[]|ArrayCollection $tickets
96
     */
97
    public function setTickets($tickets)
98
    {
99
        $this->tickets = $tickets;
100
    }
101
102
    /**
103
     * @return Enum
104
     */
105
    public function getStatus()
106
    {
107
        return $this->status;
108
    }
109
110
    /**
111
     * @param Enum $status
112
     */
113
    public function setStatus($status)
114
    {
115
        $this->status = $status;
116
    }
117
118
    /**
119
     * Add Ticket
120
     *
121
     * @param Ticket $ticket
122
     * @return CustomerOrder
123
     */
124
    public function addTicket(Ticket $ticket)
125
    {
126
        if ($this->isStatusPaid()) {
127
            throw new \InvalidArgumentException('Order already paid. Impossible to add new ticket.');
128
        }
129
        $this->tickets[] = $ticket;
130
131
        return $this;
132
    }
133
134
    /**
135
     * @param Ticket $ticket
136
     */
137
    public function removeTicket(Ticket $ticket)
138
    {
139
        if ($this->isStatusPaid()) {
140
            throw new \InvalidArgumentException('Order already pai. Impossible to remove the ticket.');
141
        }
142
        $this->tickets->removeElement($ticket);
143
    }
144
145
    /**
146
     * @return bool
147
     */
148
    private function isStatusPaid()
149
    {
150
        return $this->status === self::STATUS_PAID;
151
    }
152
153
    /**
154
     * @return array
155
     */
156
    public static function getStatuses()
157
    {
158
        return [
159
            self::STATUS_OPENED,
160
            self::STATUS_CLOSED,
161
            self::STATUS_PAID,
162
            self::STATUS_PENDING,
163
            self::STATUS_REJECTED,
164
        ];
165
    }
166
167
    /**
168
     * Set customer
169
     *
170
     * @param \AppBundle\Entity\Customer $customer
171
     *
172
     * @return CustomerOrder
173
     */
174
    public function setCustomer(\AppBundle\Entity\Customer $customer = null)
175
    {
176
        $this->customer = $customer;
177
178
        return $this;
179
    }
180
181
    /**
182
     * Get customer
183
     *
184
     * @return \AppBundle\Entity\Customer
185
     */
186
    public function getCustomer()
187
    {
188
        return $this->customer;
189
    }
190
}
191