Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
8 / 10
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
SyncPermissionsStrategy
80.00% covered (warning)
80.00%
8 / 10
33.33% covered (danger)
33.33%
1 / 3
5.20
0.00% covered (danger)
0.00%
0 / 1
 normalizeRequest
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getPermissionsToAdd
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getPermissionsToRemove
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2020 (original work) Open Assessment Technologies SA;
19 *
20 */
21
22declare(strict_types=1);
23
24namespace oat\taoDacSimple\model;
25
26class SyncPermissionsStrategy extends PermissionsStrategyAbstract
27{
28    public function normalizeRequest(array $currentPrivileges, array $privilegesToSet): array
29    {
30        // we are going to add everything what current item has and remove the rest
31        return [
32            'add' => $privilegesToSet,
33            'remove' => [],
34        ];
35    }
36
37    public function getPermissionsToAdd(array $currentPrivileges, array $addRemove): array
38    {
39        if (empty($addRemove['add'])) {
40            return [];
41        }
42
43        // we are adding everything except we already have
44        return $this->arrayDiffRecursive($addRemove['add'], $currentPrivileges);
45    }
46
47    public function getPermissionsToRemove(array $currentPrivileges, array $addRemove): array
48    {
49        if (empty($addRemove['add'])) {
50            return [];
51        }
52
53        // we are removing everything we do not need
54        return $this->arrayDiffRecursive($currentPrivileges, $addRemove['add']);
55    }
56}