Completed
Push — master ( a5acb0...57b2d8 )
by Raffael
22:45 queued 18:41
created

Map   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 2
dl 0
loc 27
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B map() 0 21 11
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * tubee
7
 *
8
 * @copyright   Copryright (c) 2017-2019 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Tubee\Workflow;
13
14
use MongoDB\BSON\UTCDateTimeInterface;
15
use Tubee\AttributeMap\AttributeMapInterface;
16
use Tubee\Helper;
17
18
class Map
19
{
20
    /**
21
     * Map.
22
     */
23
    public static function map(AttributeMapInterface $map, array $object, array $mongodb_object, UTCDateTimeInterface $ts): Iterable
0 ignored issues
show
Unused Code introduced by
The parameter $ts 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...
24
    {
25
        $object = Helper::associativeArrayToPath($object);
26
        $mongodb_object = Helper::associativeArrayToPath($mongodb_object);
27
28
        foreach ($map->getMap() as $name => $value) {
29
            $name = $value['name'];
30
31
            $exists = isset($mongodb_object[$name]);
32
            if ($value['ensure'] === WorkflowInterface::ENSURE_EXISTS && $exists === true) {
33
                continue;
34
            }
35
            if (($value['ensure'] === WorkflowInterface::ENSURE_LAST || $value['ensure'] === WorkflowInterface::ENSURE_EXISTS) && isset($object[$name])) {
36
                $mongodb_object[$name] = $object[$name];
37
            } elseif ($value['ensure'] === WorkflowInterface::ENSURE_ABSENT && isset($mongodb_object[$name]) || !isset($object[$name]) && isset($mongodb_object[$name])) {
38
                unset($mongodb_object[$name]);
39
            }
40
        }
41
42
        return Helper::pathArrayToAssociative($mongodb_object);
43
    }
44
}
45