Test Failed
Push — master ( 4c546d...964b0c )
by Maximo
11:32 queued 04:39
created

CustomFieldsMapper::getValues()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 6
rs 10
c 1
b 0
f 0
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
31
        $customFieldDto->created_at = $customField->created_at;
32
        $customFieldDto->updated_at = $customField->updated_at;
33
        $customFieldDto->is_deleted = $customField->is_deleted;
34
35
        return $customFieldDto;
36
    }
37
38
    /**
39
     * Format the value array of a custom field.
40
     *
41
     * @param array $values
42
     * @return array
43
     */
44
    private function getValues(Resultset $values): array
45
    {
46
        $newValue = [];
47
        foreach ($values as $value) {
48
            $newValue[] = [
49
                'label' => $value->label,
50
                'value' => $value->value
51
            ];
52
        }
53
54
        return $newValue;
55
    }
56
}
57