Test Failed
Branch add-core-tests (a060d8)
by Rafael
05:48
created

CustomFieldsMapper::mapToObject()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 5
eloc 14
c 2
b 0
f 1
nc 16
nop 3
dl 0
loc 19
ccs 0
cts 16
cp 0
crap 30
rs 9.4888
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Mapper;
6
7
use AutoMapperPlus\CustomMapper\CustomMapper;
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
     * @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...
17
     */
18
    public function mapToObject($customField, $customFieldDto, array $context = [])
19
    {
20
        $customFieldDto->id = $customField->getId();
21
        $customFieldDto->users_id = $customField->users_id;
22
        $customFieldDto->companies_id = $customField->companies_id;
23
        $customFieldDto->name = $customField->name;
24
        $customFieldDto->label = $customField->label;
25
        $customFieldDto->custom_fields_modules_id = $customField->custom_fields_modules_id;
26
        $customFieldDto->fields_type_id = $customField->fields_type_id;
27
28
        $customFieldDto->attributes = !empty($customField->attributes) && isJson($customField->attributes) ? json_decode($customField->attributes) : null;
29
        $customFieldDto->values = $customField->values ? $this->getValues($customField->values) : null;
30
        $customFieldDto->type = $customField->type ? $customField->type->toArray() : null;
31
32
        $customFieldDto->created_at = $customField->created_at;
33
        $customFieldDto->updated_at = $customField->updated_at;
34
        $customFieldDto->is_deleted = $customField->is_deleted;
35
36
        return $customFieldDto;
37
    }
38
39
    /**
40
     * Format the value array of a custom field.
41
     *
42
     * @param array $values
43
     * @return array
44
     */
45
    private function getValues(Resultset $values): array
46
    {
47
        $newValue = [];
48
        foreach ($values as $value) {
49
            $newValue[] = [
50
                'label' => $value->label,
51
                'value' => $value->value
52
            ];
53
        }
54
55
        return $newValue;
56
    }
57
}
58