Member::setPhoneNumber()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Storgman.
8
 *
9
 * Storgman is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Storgman is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Storgman.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Storgman
23
 * @copyright Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/storgman/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace Angelov\Storgman\Members;
29
30
use Angelov\Storgman\Faculties\Faculty;
31
use Angelov\Storgman\Meetings\Meeting;
32
use Angelov\Storgman\Membership\Fee;
33
use Carbon\Carbon;
34
use DateTime;
35
use Illuminate\Auth\Authenticatable;
36
use Illuminate\Auth\Passwords\CanResetPassword;
37
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableInterface;
38
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordInterface;
39
use Illuminate\Database\Eloquent\Model;
40
41
class Member extends Model implements AuthenticatableInterface, CanResetPasswordInterface
42
{
43
    use Authenticatable, CanResetPassword;
44
45
    protected $table = 'members';
46
47
    protected $hidden = ['password', 'remember_token'];
48
49
    protected $appends = ['full_name', 'membership_status', 'membership_expiration_date'];
50
51
    protected $dates = ['birthday'];
52
53
    public function getId()
54
    {
55
        return $this->getAttribute('id');
56
    }
57
58
    public function getEmail()
59
    {
60
        return $this->getAttribute('email');
61
    }
62
63
    /**
64
     * @param string $email
65
     */
66
    public function setEmail($email)
67
    {
68
        $this->setAttribute('email', $email);
69
    }
70
71
    public function getPassword()
72
    {
73
        return $this->getAttribute('password');
74
    }
75
76
    /**
77
     * @param string $password
78
     */
79
    public function setPassword($password)
80
    {
81
        $this->setAttribute('password', $password);
82
    }
83
84
    public function getFirstName()
85
    {
86
        return $this->getAttribute('first_name');
87
    }
88
89
    /**
90
     * @param string $firstName
91
     */
92
    public function setFirstName($firstName)
93
    {
94
        $this->setAttribute('first_name', $firstName);
95
    }
96
97
    public function getLastName()
98
    {
99
        return $this->getAttribute('last_name');
100
    }
101
102
    /**
103
     * @param string $lastName
104
     */
105
    public function setLastName($lastName)
106
    {
107
        $this->setAttribute('last_name', $lastName);
108
    }
109
110
    public function getFullName()
111
    {
112
        return $this->getFirstName() . " " . $this->getLastName();
113
    }
114
115
    public function faculty()
116
    {
117
        return $this->belongsTo(Faculty::class, 'faculty_id');
118
    }
119
120
    /**
121
     * @return Faculty
122
     */
123
    public function getFaculty()
124
    {
125
        return $this->faculty;
0 ignored issues
show
Documentation introduced by
The property faculty does not exist on object<Angelov\Storgman\Members\Member>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
126
    }
127
128
    public function setFaculty(Faculty $faculty)
129
    {
130
        $this->faculty()->associate($faculty);
131
    }
132
133
    public function getFieldOfStudy()
134
    {
135
        return $this->getAttribute('field_of_study');
136
    }
137
138
    /**
139
     * @param string $field
140
     */
141
    public function setFieldOfStudy($field)
142
    {
143
        $this->setAttribute('field_of_study', $field);
144
    }
145
146
    public function getYearOfGraduation()
147
    {
148
        return $this->getAttribute('year_of_graduation');
149
    }
150
151
    /**
152
     * @param int $year
153
     */
154
    public function setYearOfGraduation($year)
155
    {
156
        $this->setAttribute('year_of_graduation', $year);
157
    }
158
159
    public function getPhoto()
160
    {
161
        $photo = $this->getAttribute('photo');
162
163
        return ($photo) ? $photo : "default-member-photo.png";
164
    }
165
166
    /**
167
     * @param string $photoFileName
168
     */
169
    public function setPhoto($photoFileName)
170
    {
171
        $this->setAttribute('photo', $photoFileName);
172
    }
173
174
    /**
175
     * @return Carbon
176
     */
177
    public function getBirthday()
178
    {
179
        return $this->getAttribute('birthday');
180
    }
181
182
    public function setBirthday(DateTime $birthday)
183
    {
184
        $this->setAttribute('birthday', $birthday);
185
    }
186
187
    /**
188
     * @return int
189
     */
190
    public function getAge()
191
    {
192
        return $this->getBirthday()->age;
193
    }
194
195
    public function isBoardMember()
196
    {
197
        return $this->getAttribute('board_member');
198
    }
199
200
    /**
201
     * @param boolean $isBoardMember
202
     */
203
    public function setBoardMember($isBoardMember)
204
    {
205
        $this->setAttribute('board_member', $isBoardMember);
206
    }
207
208
    public function getPositionTitle()
209
    {
210
        return $this->getAttribute('position_title');
211
    }
212
213
    /**
214
     * @param string $title
215
     */
216
    public function setPositionTitle($title)
217
    {
218
        $this->setAttribute('position_title', $title);
219
    }
220
221
    /**
222
     * @return Carbon
223
     */
224
    public function getCreatedAt()
225
    {
226
        return $this->getAttribute('created_at');
227
    }
228
229
    /**
230
     * @return Carbon
231
     */
232
    public function getUpdatedAt()
233
    {
234
        return $this->getAttribute('updated_at');
235
    }
236
237
    public function getFacebook()
238
    {
239
        return $this->getAttribute('facebook');
240
    }
241
242
    /**
243
     * @param string $profile
244
     */
245
    public function setFacebook($profile)
246
    {
247
        $this->setAttribute('facebook', $profile);
248
    }
249
250
    public function getTwitter()
251
    {
252
        return $this->getAttribute('twitter');
253
    }
254
255
    /**
256
     * @param string $profile
257
     */
258
    public function setTwitter($profile)
259
    {
260
        $this->setAttribute('twitter', $profile);
261
    }
262
263
    public function getGooglePlus()
264
    {
265
        return $this->getAttribute('google_plus');
266
    }
267
268
    /**
269
     * @param string $profile
270
     */
271
    public function setGooglePlus($profile)
272
    {
273
        $this->setAttribute('google_plus', $profile);
274
    }
275
276
    public function getPhoneNumber()
277
    {
278
        return $this->getAttribute('phone');
279
    }
280
281
    /**
282
     * @param string $number
283
     */
284
    public function setPhoneNumber($number)
285
    {
286
        $this->setAttribute('phone', $number);
287
    }
288
289
    public function getWebsite()
290
    {
291
        return $this->getAttribute('website');
292
    }
293
294
    /**
295
     * @param string $url
296
     */
297
    public function setWebsite($url)
298
    {
299
        $this->setAttribute('website', $url);
300
    }
301
302
    public function isAlumniMember()
303
    {
304
        return $this->getAttribute('alumni');
305
    }
306
307
    /**
308
     * @param boolean $isAlumni
309
     */
310
    public function setAlumniMember($isAlumni)
311
    {
312
        $this->setAttribute('alumni', $isAlumni);
313
    }
314
315
    public function isApproved()
316
    {
317
        return $this->getAttribute('approved');
318
    }
319
320
    /**
321
     * @param boolean $isApproved
322
     */
323
    public function setApproved($isApproved)
324
    {
325
        $this->setAttribute('approved', $isApproved);
326
    }
327
328
    /**
329
     * Membership fees paid by the member
330
     *
331
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
332
     */
333
    public function fees()
334
    {
335
        return $this->hasMany(Fee::class);
336
    }
337
338
    /**
339
     * @return Fee[]
340
     */
341
    public function getFees()
342
    {
343
        return $this->fees;
0 ignored issues
show
Documentation introduced by
The property fees does not exist on object<Angelov\Storgman\Members\Member>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
344
    }
345
346
    /**
347
     * @return Carbon
348
     */
349
    public function getExpirationDate()
350
    {
351
        $fee = $this->getLatestFee();
352
353
        return (!$fee) ? null : $fee->getToDate();
354
    }
355
356
    /**
357
     * @return Carbon
358
     */
359
    public function getJoiningDate()
360
    {
361
        $fee = $this->getFirstFee();
362
363
        return ($fee) ? $fee->getFromDate() : $this->getCreatedAt();
364
    }
365
366
    /**
367
     * @param string $order ASC or DESC
368
     * @return Fee
369
     */
370
    private function getFeeByOrder($order)
371
    {
372
        $fee = $this->fees()->orderBy('to_date', $order)->first();
373
374
        return $fee;
375
    }
376
377
    /**
378
     * @return Fee
379
     */
380
    public function getLatestFee()
381
    {
382
        return $this->getFeeByOrder("DESC");
383
    }
384
385
    /**
386
     * @return Fee
387
     */
388
    public function getFirstFee()
389
    {
390
        return $this->getFeeByOrder("ASC");
391
    }
392
393
    /**
394
     * @return bool
395
     */
396
    public function isActive()
397
    {
398
        $expirationDate = $this->getExpirationDate();
399
400
        if (!$expirationDate) {
401
            return false;
402
        }
403
404
        $today = new DateTime();
405
406
        return $today < $expirationDate;
407
    }
408
409
    /**
410
     * @return string
411
     */
412
    public function getMembershipStatus()
413
    {
414
        return ($this->isActive()) ? "Active" : "Inactive";
415
    }
416
417
    /**
418
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
419
     */
420
    public function attendedMeetings()
421
    {
422
        return $this->belongsToMany(Meeting::class);
423
    }
424
425
    /**
426
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
427
     */
428
    public function createdMeetings()
429
    {
430
        return $this->hasMany(Meeting::class);
431
    }
432
}
433