Passed
Push — master ( ca2fb0...194055 )
by Florian
01:49
created

Organisation::getFutureRevenueSum()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[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 App\Entity;
13
14
use App\Entity\Base\BaseEntity;
15
use App\Entity\Traits\IdTrait;
16
use App\Form\Type\SemesterType;
17
use Doctrine\Common\Collections\ArrayCollection;
18
use Doctrine\ORM\Mapping as ORM;
19
use Ramsey\Uuid\Uuid;
20
21
/**
22
 * an event determines how the questionnaire looks like.
23
 *
24
 * @ORM\Entity()
25
 * @ORM\HasLifecycleCallbacks
26
 */
27
class Organisation extends BaseEntity
28
{
29
    use IdTrait;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Column(type="text")
35
     */
36
    private $name;
37
38
    /**
39
     * @var string
40
     *
41
     * @ORM\Column(type="text")
42
     */
43
    private $email;
44
45
    /**
46
     * @var int
47
     *
48
     * @ORM\Column(type="integer")
49
     */
50
    private $relationSinceSemester;
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(type="string")
56
     */
57
    private $authenticationCode;
58
59
    /**
60
     * @var Event[]|ArrayCollection
61
     *
62
     * @ORM\OneToMany(targetEntity="Event", mappedBy="organisation")
63
     * @ORM\OrderBy({"semester" = "DESC", "startDate" = "DESC", "endDate" = "DESC"})
64
     */
65
    private $events;
66
67
    /**
68
     * @var SemesterReport[]|ArrayCollection
69
     *
70
     * @ORM\OneToMany(targetEntity="SemesterReport", mappedBy="organisation")
71
     * @ORM\OrderBy({"semester" = "DESC"})
72
     */
73
    private $semesterReports;
74
75
    public function __construct()
76
    {
77
        $this->events = new ArrayCollection();
78
        $this->semesterReports = new ArrayCollection();
79
    }
80
81
    public function getName(): string
82
    {
83
        return $this->name;
84
    }
85
86
    public function setName(string $name): void
87
    {
88
        $this->name = $name;
89
    }
90
91
    public function getEmail(): string
92
    {
93
        return $this->email;
94
    }
95
96
    public function setEmail(string $email): void
97
    {
98
        $this->email = $email;
99
    }
100
101
    public function getRelationSinceSemester(): int
102
    {
103
        return $this->relationSinceSemester;
104
    }
105
106
    public function setRelationSinceSemester(int $relationSinceSemester): void
107
    {
108
        $this->relationSinceSemester = $relationSinceSemester;
109
    }
110
111
    public function getAuthenticationCode(): string
112
    {
113
        return $this->authenticationCode;
114
    }
115
116
    public function getCurrentSemesterReport(): ?SemesterReport
117
    {
118
        $currentSemester = SemesterType::getCurrentSemester();
119
        foreach ($this->getSemesterReports() as $semesterReport) {
120
            if ($semesterReport->getSemester() === $currentSemester) {
121
                return $semesterReport;
122
            }
123
        }
124
125
        return null;
126
    }
127
128
    /**
129
     * @var Event[]
130
     */
131
    private $futureEvents = null;
132
133
    private function ensureFutureEventsPopulated()
134
    {
135
        if ($this->futureEvents !== null) {
136
            return;
137
        }
138
139
        $this->futureEvents = [];
140
141
        $currentSemester = SemesterType::getCurrentSemester();
142
        foreach ($this->getEvents() as $event) {
143
            if ($event->getSemester() >= $currentSemester) {
144
                $this->futureEvents[] = $event;
145
            }
146
        }
147
    }
148
149
    public function getFutureEventCount(): int
150
    {
151
        $this->ensureFutureEventsPopulated();
152
153
        return \count($this->futureEvents);
154
    }
155
156
    public function getFutureRevenueSum(): int
157
    {
158
        $this->ensureFutureEventsPopulated();
159
160
        $revenueSum = 0;
161
        foreach ($this->futureEvents as $futureEvent) {
162
            $revenueSum += $futureEvent->getRevenue();
163
        }
164
165
        return $revenueSum;
166
    }
167
168
    public function getFutureExpenditureSum(): int
169
    {
170
        $this->ensureFutureEventsPopulated();
171
172
        $expenditureSum = 0;
173
        foreach ($this->futureEvents as $futureEvent) {
174
            $expenditureSum += $futureEvent->getExpenditure();
175
        }
176
177
        return $expenditureSum;
178
    }
179
180
    public function futureFinancialSupport(): bool
181
    {
182
        $this->ensureFutureEventsPopulated();
183
184
        foreach ($this->futureEvents as $futureEvent) {
185
            if ($futureEvent->isNeedFinancialSupport()) {
186
                return true;
187
            }
188
        }
189
190
        return false;
191
    }
192
193
    /**
194
     * @throws \Exception
195
     */
196
    public function setAuthenticationCode(string $authenticationCode)
197
    {
198
        $this->authenticationCode = $authenticationCode;
199
    }
200
201
    /**
202
     * @throws \Exception
203
     */
204
    public function generateAuthenticationCode()
205
    {
206
        $this->authenticationCode = Uuid::uuid4();
0 ignored issues
show
Documentation Bug introduced by
It seems like Ramsey\Uuid\Uuid::uuid4() of type Ramsey\Uuid\UuidInterface is incompatible with the declared type string of property $authenticationCode.

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...
207
    }
208
209
    /**
210
     * @return Event[]|ArrayCollection
211
     */
212
    public function getEvents()
213
    {
214
        return $this->events;
215
    }
216
217
    /**
218
     * @return SemesterReport[]|ArrayCollection
219
     */
220
    public function getSemesterReports()
221
    {
222
        return $this->semesterReports;
223
    }
224
}
225