Test Failed
Pull Request — master (#160)
by Maximo
06:15
created

UserMapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 65
c 1
b 0
f 1
dl 0
loc 93
ccs 0
cts 72
cp 0
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A accesList() 0 10 3
B mapToObject() 0 66 4
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
12
/**
13
 * Class UserMapper.
14
 *
15
 * @package Canvas\Mapper
16
 */
17
class UserMapper extends CustomMapper
18
{
19
    use RelationshipTrait;
20
21
    /**
22
     * @param Users $user
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Users 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...
23
     * @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...
24
     * @return Canvas\Dto\User
25
     */
26
    public function mapToObject($user, $userDto, array $context = [])
27
    {
28
        if (is_array($user)) {
0 ignored issues
show
introduced by
The condition is_array($user) is always false.
Loading history...
29
            $user = (object) $user;
30
        }
31
32
        $userDto->id = $user->id;
33
        $userDto->active_subscription_id = $user->active_subscription_id;
34
        $userDto->card_brand = $user->card_brand;
35
        $userDto->cell_phone_number = $user->cell_phone_number;
36
        $userDto->city_id = $user->city_id;
37
        $userDto->country_id = $user->country_id;
38
        $userDto->created_at = $user->created_at;
39
        $userDto->default_company = $user->default_company;
40
        $userDto->default_company_branch = $user->default_company_branch;
41
        $userDto->displayname = $user->displayname;
42
        $userDto->dob = $user->dob;
43
        $userDto->email = $user->email;
44
        $userDto->firstname = $user->firstname;
45
        $userDto->interest = $user->interest;
46
        $userDto->karma = $user->karma;
47
        $userDto->language = $user->language;
48
        $userDto->lastname = $user->lastname;
49
        $userDto->lastvisit = $user->lastvisit;
50
        $userDto->location = $user->location;
51
        $userDto->phone_number = $user->phone_number;
52
        $userDto->profile_header = $user->profile_header;
53
        $userDto->profile_header_mobile = $user->profile_header_mobile;
54
        $userDto->profile_image = $user->profile_image;
55
        $userDto->profile_image_mobile = $user->profile_image_mobile;
56
        $userDto->profile_image_thumb = $user->profile_image_thumb;
57
        $userDto->profile_privacy = $user->profile_privacy;
58
        $userDto->profile_remote_image = $user->profile_remote_image;
59
        $userDto->registered = $user->registered;
60
        $userDto->roles_id = $user->roles_id;
61
        $userDto->session_id = $user->session_id;
62
        $userDto->session_key = $user->session_key;
63
        $userDto->session_page = $user->session_page;
64
        $userDto->session_time = $user->session_time;
65
        $userDto->sex = $user->sex;
66
        $userDto->state_id = $user->state_id;
67
        $userDto->status = $user->status;
68
        $userDto->stripe_id = $user->stripe_id;
69
        $userDto->system_modules_id = $user->system_modules_id;
70
        $userDto->timezone = $user->timezone;
71
        $userDto->trial_ends_at = $user->trial_ends_at;
72
        $userDto->updated_at = $user->updated_at;
73
        $userDto->user_active = $user->user_active;
74
        $userDto->user_last_login_try = $user->user_last_login_try;
75
        $userDto->user_level = $user->user_level;
76
        $userDto->user_login_tries = $user->user_login_tries;
77
        $userDto->votes = $user->votes;
78
        $userDto->votes_points = $user->votes_points;
79
        $userDto->welcome = $user->welcome;
80
        $userDto->photo = $user->photo;
81
82
        $this->getRelationships($user, $userDto, $context);
83
84
        if (is_array($userDto->roles)) {
85
            if (!isset($userDto->roles[0])) {
86
                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...
87
            }
88
        }
89
90
        $this->accesList($userDto);
91
        return $userDto;
92
    }
93
94
    /**
95
     * Attach acces list to the user
96
     *
97
     * @param object $userDto
98
     * @return void
99
     */
100
    private function accesList(object $userDto): void
101
    {
102
        $accesList = AccessList::find([
103
            'conditions' => 'roles_name = ?0 and apps_id = ?1 and allowed = 0',
104
            'bind' => [$userDto->roles[0]->name, Di::getDefault()->getApp()->getId()]
105
        ]);
106
107
        if (count($accesList) > 0) {
108
            foreach ($accesList as $access) {
109
                $userDto->access_list[strtolower($access->resources_name)][$access->access_name] = 0;
110
            }
111
        }
112
    }
113
}
114