Passed
Push — master ( 34beb8...79bf97 )
by Alberto
14:24 queued 13s
created

ParentsComponent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A addRelated() 0 8 2
1
<?php
2
declare(strict_types=1);
3
/**
4
 * BEdita, API-first content management framework
5
 * Copyright 2023 Atlas Srl, Chialab Srl
6
 *
7
 * This file is part of BEdita: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as published
9
 * by the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
13
 */
14
15
namespace App\Controller\Component;
16
17
use App\Utility\ApiClientTrait;
18
use Cake\Controller\Component;
19
20
/**
21
 * Parents component.
22
 * This component is used to add/remove parents to a folder.
23
 */
24
class ParentsComponent extends Component
25
{
26
    use ApiClientTrait;
27
28
    /**
29
     * Add parent to a folder.
30
     *
31
     * @param string $folderId Folder ID.
32
     * @param array $parents Parent objects as id/type pairs.
33
     * @return array
34
     */
35
    public function addRelated(string $folderId, array $parents): array
36
    {
37
        $results = [];
38
        foreach ($parents as $parent) {
39
            $results[] = $this->getClient()->replaceRelated($folderId, 'folders', 'parent', $parent);
40
        }
41
42
        return $results;
43
    }
44
}
45