Completed
Push — master ( b64fc1...5651bd )
by Raffael
16:20 queued 08:39
created

Map   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 2
dl 0
loc 31
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C map() 0 25 12
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
            if ($value['skip'] === true) {
32
                continue;
33
            }
34
35
            $exists = isset($mongodb_object[$name]);
36
            if ($value['ensure'] === WorkflowInterface::ENSURE_EXISTS && $exists === true) {
37
                continue;
38
            }
39
            if (($value['ensure'] === WorkflowInterface::ENSURE_LAST || $value['ensure'] === WorkflowInterface::ENSURE_EXISTS) && isset($object[$name])) {
40
                $mongodb_object[$name] = $object[$name];
41
            } elseif ($value['ensure'] === WorkflowInterface::ENSURE_ABSENT && isset($mongodb_object[$name]) || !isset($object[$name]) && isset($mongodb_object[$name])) {
42
                unset($mongodb_object[$name]);
43
            }
44
        }
45
46
        return Helper::pathArrayToAssociative($mongodb_object);
47
    }
48
}
49