grants::cd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc;
13
14
/**
15
 * @package arc-grants
16
 * @requires \arc\path;
17
 * @requires \arc\tree;
18
 * @requires \arc\context;
19
 * @method static GrantsTree cd(string $path)
20
 * @method static GrantsTree switchUser(string $user, array $groups)
21
 * @method static GrantsTree setUserGrants(string $grants)
22
 * @method static GrantsTree setGroupGrants(string $group, string $grants)
23
 * @method static bool check(string $grant)
24
 * @method static array ls()
25
 */
26
27
final class grants
28
{
29 2
    public static function getGrantsTree()
30
    {
31 2
        $context = \arc\context::$context;
32 2
        if (!$context->arcUser) {
33 1
            $context->arcUser = 'public';
34 1
        }
35 2
        if (!$context->arcGroups) {
36 1
            $context->arcGroups  = [ 'public' ];
37 1
        }
38 2
        if (!$context->arcGrants) {
39 1
            $context->arcGrants = new grants\GrantsTree( \arc\tree::expand()->cd( $context->arcPath ), $context->arcUser, $context->arcGroups );
40 1
        }
41
42 2
        return $context->arcGrants;
43
    }
44
45 1
    public static function cd($path=null) {
46 1
        \arc\context::$context->arcGrants = self::getGrantsTree()->cd($path);
47 1
        return \arc\context::$context->arcGrants;
48
    }
49
50 1
    public static function switchUser($user) {
51 1
        \arc\context::$context->arcGrants = self::getGrantsTree()->switchUser($user);
52 1
        return \arc\context::$context->arcGrants;
53
    }
54
55 2
    public static function __callStatic($name, $params) {
56 2
        return call_user_func_array( [self::getGrantsTree(), $name], $params );
57
    }
58
}
59