Failed Conditions
Pull Request — master (#330)
by Rafael
02:44
created

CustomFieldsModulesMapper::mapToObject()   B

Complexity

Conditions 7
Paths 2

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 2
nop 3
dl 0
loc 37
rs 8.3946
c 0
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;
10
use Phalcon\Di;
11
12
class CustomFieldsModulesMapper extends CustomMapper
13
{
14
    /**
15
     * @param Canvas\Models\FileSystem $file
0 ignored issues
show
Bug introduced by
There is no parameter named $file. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
16
     * @param Canvas\Dto\Files $fileDto
0 ignored issues
show
Bug introduced by
There is no parameter named $fileDto. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
     * @return Files
18
     */
19
    public function mapToObject($customFieldsModules, $customFieldsModulesDto, array $context = [])
20
    {
21
        $customFieldsArray = [];
22
        $customFieldsModulesDto->id = $customFieldsModules->getId();
23
        $customFieldsModulesDto->apps_id = $customFieldsModules->apps_id;
24
        $customFieldsModulesDto->name = $customFieldsModules->name;
25
        $customFieldsModulesDto->created_at = $customFieldsModules->created_at;
26
        $customFieldsModulesDto->updated_at = $customFieldsModules->updated_at;
27
        $customFieldsModulesDto->is_deleted = $customFieldsModules->is_deleted;
28
29
        if (preg_match("/\/([0-9]+)(?=[^\/]*$)/", Di::getDefault()->getRequest()->getURI())) {
30
            foreach ($customFieldsModules->getFields() as $customField) {
31
                $customFieldsArray['id'] = $customField->getId();
32
                $customFieldsArray['apps_id'] = $customField->apps_id;
33
                $customFieldsArray['users_id'] = $customField->users_id;
34
                $customFieldsArray['companies_id'] = $customField->companies_id;
35
                $customFieldsArray['name'] = $customField->name;
36
                $customFieldsArray['label'] = $customField->label;
37
                $customFieldsArray['custom_fields_modules_id'] = $customField->custom_fields_modules_id;
38
                $customFieldsArray['fields_type_id'] = $customField->fields_type_id;
39
40
                $customFieldsArray['attributes'] = !empty($customField->attributes) && isJson($customField->attributes) ? json_decode($customField->attributes) : null;
41
                $customFieldsArray['values'] = $customField->values ? $this->getValues($customField->values) : null;
42
                $customFieldsArray['type'] = $customField->type ? $customField->type->toArray() : null;
43
44
                $customFieldsArray['created_at'] = $customField->created_at;
45
                $customFieldsArray['updated_at'] = $customField->updated_at;
46
                $customFieldsArray['is_deleted'] = $customField->is_deleted;
47
48
                $customFieldsModulesDto->custom_fields[] = $customFieldsArray;
49
            }
50
        }
51
52
        //This corresponds to the custom fields
53
54
        return $customFieldsModulesDto;
55
    }
56
57
    /**
58
     * Format the value array of a custom field.
59
     *
60
     * @param array $values
0 ignored issues
show
Documentation introduced by
Should the type for parameter $values not be Resultset?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
61
     * @return array
62
     */
63
    private function getValues(Resultset $values): array
64
    {
65
        $newValue = [];
66
        foreach ($values as $value) {
67
            $newValue[] = [
68
                'label' => $value->label,
69
                'value' => $value->value
70
            ];
71
        }
72
73
        return $newValue;
74
    }
75
}
76