Completed
Pull Request — develop (#575)
by
unknown
102:40 queued 37:52
created

MappingService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mapData() 0 14 4
A fieldMapper() 0 14 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: taachja1
5
 * Date: 04.04.17
6
 * Time: 09:50
7
 */
8
namespace Graviton\ApiBundle\Service;
9
10
11
use Graviton\ApiBundle\Manager\DatabaseManager;
12
use Graviton\ExceptionBundle\Exception\NotFoundException;
13
use Graviton\JsonSchemaBundle\Validator\InvalidJsonException;
14
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
17
class MappingService
18
{
19
    /**
20
     * Meant to map the Service data with the output
21
     * TODO move this to a real mapper class
22
     * @param $data
23
     * @param $schema
24
     * @return array
25
     */
26
    public function mapData($data, $schema)
0 ignored issues
show
Unused Code introduced by
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
    {
28
        if (empty($data)) {
29
            return $data;
30
        }
31
        if (array_key_exists('_id', $data)) {
32
            return $this->fieldMapper($data);
33
        } else {
34
            foreach ($data as &$item) {
35
                $item = $this->fieldMapper($item);
36
            }
37
        }
38
        return $data;
39
    }
40
    private function fieldMapper($data)
41
    {
42
        // Use some how $this->schema to map output
43
        $rtn = [];
44
        foreach ($data as $field => $value) {
45
            if ('_id' == $field) {
46
                $rtn['id'] = $value;
47
            } else {
48
                $rtn[$field] = $value;
49
            }
50
        }
51
52
        return $rtn;
53
    }
54
}