Passed
Branch master (4a352c)
by Allan
04:38 queued 02:31
created

Updater   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateStatuses() 0 9 1
A embedInfoToItems() 0 14 5
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Patch\DefinitionList;
7
8
use Vaimo\ComposerPatches\Patch\Definition as Patch;
9
10
class Updater
11
{
12
    /**
13
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
14
     *
15
     * @param array $patches
16
     * @param array|bool|string $update
17
     * @param bool $onlyNew
18
     * @return array
19
     */
20
    public function embedInfoToItems(array $patches, $update, $onlyNew = false)
21
    {
22
        foreach ($patches as $target => $group) {
23
            foreach (array_keys($group) as $path) {
24
                $patches[$target][$path] = is_array($update)
25
                    ? array_replace(
26
                        $patches[$target][$path],
27
                        $onlyNew ? array_diff_key($update, array_filter($patches[$target][$path])) : $update
28
                    )
29
                    : $update;
30
            }
31
        }
32
33
        return $patches;
34
    }
35
36
    public function updateStatuses(array $patches, $status)
37
    {
38
        return array_map(function (array $group) use ($status) {
39
            return array_map(function (array $patch) use ($status) {
40
                return array_replace($patch, array(
41
                    Patch::STATUS => $status
42
                ));
43
            }, $group);
44
        }, $patches);
45
    }
46
}
47