CustomFieldsModulesMapper   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 31
c 3
b 0
f 0
dl 0
loc 64
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getValues() 0 11 2
B mapToObject() 0 36 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
0 ignored issues
show
Bug introduced by
The type AutoMapperPlus\CustomMapper\CustomMapper 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...
8
use function Canvas\Core\isJson;
9
use Phalcon\Di;
10
use Phalcon\Mvc\Model\Resultset;
0 ignored issues
show
Bug introduced by
The type Phalcon\Mvc\Model\Resultset 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...
11
12
class CustomFieldsModulesMapper extends CustomMapper
13
{
14
    /**
15
     * @param Canvas\Models\FileSystem $file
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Models\FileSystem was not found. Did you mean Canvas\Models\FileSystem? If so, make sure to prefix the type with \.
Loading history...
16
     * @param Canvas\Dto\Files $fileDto
0 ignored issues
show
Bug introduced by
The type Canvas\Mapper\Canvas\Dto\Files was not found. Did you mean Canvas\Dto\Files? If so, make sure to prefix the type with \.
Loading history...
17
     *
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($customFieldsModules, $customFieldsModulesDto, array $context = [])
21
    {
22
        $customFieldsArray = [];
23
        $customFieldsModulesDto->id = $customFieldsModules->getId();
24
        $customFieldsModulesDto->apps_id = $customFieldsModules->apps_id;
25
        $customFieldsModulesDto->name = $customFieldsModules->name;
26
        $customFieldsModulesDto->created_at = $customFieldsModules->created_at;
27
        $customFieldsModulesDto->updated_at = $customFieldsModules->updated_at;
28
        $customFieldsModulesDto->is_deleted = $customFieldsModules->is_deleted;
29
30
        if (preg_match("/\/([0-9]+)(?=[^\/]*$)/", Di::getDefault()->getRequest()->getURI())) {
31
            foreach ($customFieldsModules->getFields() as $customField) {
32
                $customFieldsArray['id'] = $customField->getId();
33
                $customFieldsArray['apps_id'] = $customField->apps_id;
34
                $customFieldsArray['users_id'] = $customField->users_id;
35
                $customFieldsArray['companies_id'] = $customField->companies_id;
36
                $customFieldsArray['name'] = $customField->name;
37
                $customFieldsArray['label'] = $customField->label;
38
                $customFieldsArray['custom_fields_modules_id'] = $customField->custom_fields_modules_id;
39
                $customFieldsArray['fields_type_id'] = $customField->fields_type_id;
40
41
                $customFieldsArray['attributes'] = !empty($customField->attributes) && isJson($customField->attributes) ? json_decode($customField->attributes) : null;
42
                $customFieldsArray['values'] = $customField->values ? $this->getValues($customField->values) : null;
43
                $customFieldsArray['type'] = $customField->type ? $customField->type->toArray() : null;
44
45
                $customFieldsArray['created_at'] = $customField->created_at;
46
                $customFieldsArray['updated_at'] = $customField->updated_at;
47
                $customFieldsArray['is_deleted'] = $customField->is_deleted;
48
49
                $customFieldsModulesDto->custom_fields[] = $customFieldsArray;
50
            }
51
        }
52
53
        //This corresponds to the custom fields
54
55
        return $customFieldsModulesDto;
56
    }
57
58
    /**
59
     * Format the value array of a custom field.
60
     *
61
     * @param array $values
62
     *
63
     * @return array
64
     */
65
    private function getValues(Resultset $values) : array
66
    {
67
        $newValue = [];
68
        foreach ($values as $value) {
69
            $newValue[] = [
70
                'label' => $value->label,
71
                'value' => $value->value
72
            ];
73
        }
74
75
        return $newValue;
76
    }
77
}
78