Test Failed
Pull Request — master (#160)
by Maximo
07:12
created

UserMapper::accesList()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 6
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
8
use Canvas\Models\AccessList;
9
use Phalcon\Di;
10
use Canvas\Contracts\Mapper\RelationshipTrait;
11
use Canvas\Models\Users;
12
13
/**
14
 * Class UserMapper.
15
 *
16
 * @package Canvas\Mapper
17
 */
18
class UserMapper extends CustomMapper
19
{
20
    use RelationshipTrait;
21
22
    /**
23
     * @param Users $user
24
     * @param Canvas\Dto\User $userDto
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Dto\User was not found. Did you mean Canvas\Dto\User? If so, make sure to prefix the type with \.
Loading history...
25
     * @return Canvas\Dto\User
26
     */
27
    public function mapToObject($user, $userDto, array $context = [])
28
    {
29
        if (is_array($user)) {
0 ignored issues
show
introduced by
The condition is_array($user) is always false.
Loading history...
30
            $user = (object) $user;
31
        }
32
33
        $userDto->id = $user->id;
34
        $userDto->active_subscription_id = $user->active_subscription_id;
35
        $userDto->card_brand = $user->card_brand;
36
        $userDto->cell_phone_number = $user->cell_phone_number;
37
        $userDto->city_id = $user->city_id;
38
        $userDto->country_id = $user->country_id;
39
        $userDto->created_at = $user->created_at;
40
        $userDto->default_company = Users::getById($user->id)->getDefaultCompany()->getId();
41
        $userDto->default_company_branch = $user->default_company_branch;
42
        $userDto->displayname = $user->displayname;
43
        $userDto->dob = $user->dob;
44
        $userDto->email = $user->email;
45
        $userDto->firstname = $user->firstname;
46
        $userDto->interest = $user->interest;
47
        $userDto->karma = $user->karma;
48
        $userDto->language = $user->language;
49
        $userDto->lastname = $user->lastname;
50
        $userDto->lastvisit = $user->lastvisit;
51
        $userDto->location = $user->location;
52
        $userDto->phone_number = $user->phone_number;
53
        $userDto->profile_header = $user->profile_header;
54
        $userDto->profile_header_mobile = $user->profile_header_mobile;
55
        $userDto->profile_image = $user->profile_image;
56
        $userDto->profile_image_mobile = $user->profile_image_mobile;
57
        $userDto->profile_image_thumb = $user->profile_image_thumb;
58
        $userDto->profile_privacy = $user->profile_privacy;
59
        $userDto->profile_remote_image = $user->profile_remote_image;
60
        $userDto->registered = $user->registered;
61
        $userDto->roles_id = $user->roles_id;
62
        $userDto->session_id = $user->session_id;
63
        $userDto->session_key = $user->session_key;
64
        $userDto->session_page = $user->session_page;
65
        $userDto->session_time = $user->session_time;
66
        $userDto->sex = $user->sex;
67
        $userDto->state_id = $user->state_id;
68
        $userDto->status = $user->status;
69
        $userDto->stripe_id = $user->stripe_id;
70
        $userDto->system_modules_id = $user->system_modules_id;
71
        $userDto->timezone = $user->timezone;
72
        $userDto->trial_ends_at = $user->trial_ends_at;
73
        $userDto->updated_at = $user->updated_at;
74
        $userDto->user_active = $user->user_active;
75
        $userDto->user_last_login_try = $user->user_last_login_try;
76
        $userDto->user_level = $user->user_level;
77
        $userDto->user_login_tries = $user->user_login_tries;
78
        $userDto->votes = $user->votes;
79
        $userDto->votes_points = $user->votes_points;
80
        $userDto->welcome = $user->welcome;
81
        $userDto->photo = $user->photo;
82
83
        $this->getRelationships($user, $userDto, $context);
84
85
        if (is_array($userDto->roles)) {
86
            if (!isset($userDto->roles[0])) {
87
                throw new ServerErrorHttpException('User with no Role , please contact system admin');
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\ServerErrorHttpException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
88
            }
89
        }
90
91
        $this->accesList($userDto);
92
        return $userDto;
93
    }
94
95
    /**
96
     * Attach acces list to the user
97
     *
98
     * @param object $userDto
99
     * @return void
100
     */
101
    private function accesList(object $userDto): void
102
    {
103
        $accesList = AccessList::find([
104
            'conditions' => 'roles_name = ?0 and apps_id = ?1 and allowed = 0',
105
            'bind' => [$userDto->roles[0]->name, Di::getDefault()->getApp()->getId()]
106
        ]);
107
108
        if (count($accesList) > 0) {
109
            foreach ($accesList as $access) {
110
                $userDto->access_list[strtolower($access->resources_name)][$access->access_name] = 0;
111
            }
112
        }
113
    }
114
}
115