MembersPopulator::populateFromArray()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 38
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
c 0
b 0
f 0
rs 8.439
cc 5
eloc 24
nc 16
nop 2
1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2015, 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-2015, 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\Repositories\FacultiesRepositoryInterface;
31
use Angelov\Storgman\Members\Member;
32
use Angelov\Storgman\Members\Photos\Repositories\PhotosRepositoryInterface;
33
use DateTime;
34
use Illuminate\Contracts\Hashing\Hasher;
35
36
class MembersPopulator
37
{
38
    protected $hasher;
39
    protected $photos;
40
    protected $faculties;
41
42
    public function __construct(Hasher $hasher, PhotosRepositoryInterface $photos, FacultiesRepositoryInterface $faculties)
43
    {
44
        $this->hasher = $hasher;
45
        $this->photos = $photos;
46
        $this->faculties = $faculties;
47
    }
48
49
    public function populateFromArray(Member $member, array $data)
50
    {
51
        $member->setFirstName($data['first_name']);
52
        $member->setLastName($data['last_name']);
53
        $member->setBirthday(new DateTime($data['birthday']));
54
        $member->setEmail($data['email']);
55
56
        if ($data['password']) {
57
            $hashed = $this->hasher->make($data['password']);
58
            $member->setPassword($hashed);
59
        }
60
61
        $member->setFieldOfStudy($data['field_of_study']);
62
        $member->setYearOfGraduation($data['year_of_graduation']);
63
        $member->setBoardMember(array_get($data, 'board_member', 0) == 1);
64
65
        if (isset($data['position_title'])) {
66
            $member->setPositionTitle($data['position_title']);
67
        }
68
69
        if (isset($data['alumni_member'])) {
70
            $member->setAlumniMember($data['alumni_member'] == 1);
71
        }
72
73
        if (isset($data['faculty'])) {
74
            $faculty = $this->faculties->get($data['faculty']);
75
            $member->setFaculty($faculty);
76
        }
77
78
        $member->setFacebook($data['facebook']);
79
        $member->setTwitter($data['twitter']);
80
        $member->setGooglePlus($data['google_plus']);
81
82
        $member->setPhoneNumber($data['phone']);
83
        $member->setWebsite($data['website']);
84
85
        return $member;
86
    }
87
}
88