HeaderConverter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 18 4
1
<?php
2
3
/**
4
 * This file is part of plumphp/plum.
5
 *
6
 * (c) Florian Eckerstorfer <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Plum\Plum\Converter;
12
13
/**
14
 * HeaderConverter.
15
 *
16
 * @author    Sebastian Göttschkes <[email protected]>
17
 * @copyright 2014-2016 Florian Eckerstorfer
18
 */
19
class HeaderConverter implements ConverterInterface
20
{
21
    /** @var string[]|null */
22
    private $header = null;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function convert($item)
28
    {
29 3
        if ($this->header === null) {
30 2
            $this->header = $item;
31
32 2
            return $item;
33
        }
34
35 2
        $newItem = [];
36 2
        foreach ($item as $key => $value) {
37 2
            if (isset($this->header[$key])) {
38 2
                $key = $this->header[$key];
39 2
            }
40 2
            $newItem[$key] = $value;
41 2
        }
42
43 2
        return $newItem;
44
    }
45
}
46