CustomFieldsMapper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 48
ccs 0
cts 29
cp 0
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mapToObject() 0 20 5
A getValues() 0 11 2
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\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...
10
11
class CustomFieldsMapper extends CustomMapper
12
{
13
    /**
14
     * @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...
15
     * @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...
16
     *
17
     * @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...
18
     */
19
    public function mapToObject($customField, $customFieldDto, array $context = [])
20
    {
21
        $customFieldDto->id = $customField->getId();
22
        $customFieldDto->apps_id = $customField->apps_id;
23
        $customFieldDto->users_id = $customField->users_id;
24
        $customFieldDto->companies_id = $customField->companies_id;
25
        $customFieldDto->name = $customField->name;
26
        $customFieldDto->label = $customField->label;
27
        $customFieldDto->custom_fields_modules_id = $customField->custom_fields_modules_id;
28
        $customFieldDto->fields_type_id = $customField->fields_type_id;
29
30
        $customFieldDto->attributes = !empty($customField->attributes) && isJson($customField->attributes) ? json_decode($customField->attributes) : null;
31
        $customFieldDto->values = $customField->values ? $this->getValues($customField->values) : null;
32
        $customFieldDto->type = $customField->type ? $customField->type->toArray() : null;
33
34
        $customFieldDto->created_at = $customField->created_at;
35
        $customFieldDto->updated_at = $customField->updated_at;
36
        $customFieldDto->is_deleted = $customField->is_deleted;
37
38
        return $customFieldDto;
39
    }
40
41
    /**
42
     * Format the value array of a custom field.
43
     *
44
     * @param array $values
45
     *
46
     * @return array
47
     */
48
    private function getValues(Resultset $values) : array
49
    {
50
        $newValue = [];
51
        foreach ($values as $value) {
52
            $newValue[] = [
53
                'label' => $value->label,
54
                'value' => $value->value
55
            ];
56
        }
57
58
        return $newValue;
59
    }
60
}
61