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

NotificationMapper::mapToObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 24
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 30
ccs 0
cts 27
cp 0
crap 6
rs 9.536
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
8
use Canvas\Models\SystemModules;
9
use ReflectionClass;
10
11
// You can either extend the CustomMapper, or just implement the MapperInterface
12
// directly.
13
class NotificationMapper extends CustomMapper
14
{
15
    /**
16
     * @param Canvas\Models\Notification $notification
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Models\Notification 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...
17
     * @param Canvas\Dto\notificationDto $notificationDto
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Dto\notificationDto 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...
18
     * @return Files
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Files 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...
19
     */
20
    public function mapToObject($notification, $notificationDto, array $context = [])
21
    {
22
        $notificationDto->id = $notification->getId();
23
        $notificationDto->type = $notification->type->name;
24
        $notificationDto->users_id = $notification->users_id;
25
        $notificationDto->from_users_id = $notification->from_users_id;
26
        $notificationDto->companies_id = $notification->companies_id;
27
        $notificationDto->apps_id = $notification->apps_id;
28
        $notificationDto->system_modules_id = $notification->system_modules_id;
29
        $notificationDto->notification_type_id = $notification->notification_type_id;
30
        $notificationDto->entity_id = $notification->entity_id;
31
        $notificationDto->content = $notification->content;
32
        $notificationDto->read = $notification->read;
33
        $notificationDto->created_at = $notification->created_at;
34
        $notificationDto->updated_at = $notification->updated_at;
35
        $notificationDto->from = [
36
            'user_id' => $notification->from->getId(),
37
            'displayname' => $notification->from->displayname,
38
            'avatar' => $notification->from->photo ? $notification->from->photo->url : null,
39
        ];
40
41
        $systemModule = SystemModules::getById($notification->system_modules_id);
42
        $systemModuleEntity = new $systemModule->model_name;
43
        $entity = $systemModuleEntity::findFirst($notification->entity_id);
44
        $notificationDto->entity = $entity->toArray();
45
        $reflect = new ReflectionClass($systemModuleEntity);
46
        $notificationDto->entity['type'] = $reflect->getShortName();
47
        
48
49
        return $notificationDto;
50
    }
51
}
52