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

Updater::embedInfoToItems()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 4
nop 3
dl 0
loc 14
rs 9.6111
c 0
b 0
f 0
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