Completed
Push — master ( cd3b2e...50c111 )
by Craig
07:10
created

PermissionAlwaysApi::hasPermission()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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 Zikula\PermissionsModule\Api;
13
14
use Zikula\PermissionsModule\Api\ApiInterface\PermissionApiInterface;
15
16
/**
17
 * Class PermissionAlwaysApi
18
 *
19
 * This class exists for testing and to ensure a functional Api is provided in a default situation.
20
 * ALL hasPermission tests return TRUE regardless of settings.
21
 * Access level names are returned untranslated.
22
 * Permissions cannot be reset for a user.
23
 */
24
class PermissionAlwaysApi implements PermissionApiInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function hasPermission($component = null, $instance = null, $level = ACCESS_NONE, $user = null)
30
    {
31
        return true;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function accessLevelNames($level = null)
38
    {
39 View Code Duplication
        if (isset($level) && !is_numeric($level)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
            throw new \InvalidArgumentException();
41
        } elseif (isset($level)) {
42
            $level = intval($level);
43
        }
44
45
        $accessNames = [
46
            ACCESS_INVALID => 'Invalid',
47
            ACCESS_NONE => 'No access',
48
            ACCESS_OVERVIEW => 'Overview access',
49
            ACCESS_READ => 'Read access',
50
            ACCESS_COMMENT => 'Comment access',
51
            ACCESS_MODERATE => 'Moderate access',
52
            ACCESS_EDIT => 'Edit access',
53
            ACCESS_ADD => 'Add access',
54
            ACCESS_DELETE => 'Delete access',
55
            ACCESS_ADMIN => 'Admin access',
56
        ];
57
58
        return isset($level) ? $accessNames[$level] : $accessNames;
0 ignored issues
show
Bug Compatibility introduced by
The expression isset($level) ? $accessN...$level] : $accessNames; of type string|string[] adds the type string[] to the return on line 58 which is incompatible with the return type declared by the interface Zikula\PermissionsModule...rface::accessLevelNames of type string.
Loading history...
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function resetPermissionsForUser($uid)
65
    {
66
        // nothing to do
67
    }
68
}
69