Completed
Branch master (2665c2)
by Pierre-Henry
33:16
created

AclResource::__get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @title            Acl Resource Class
4
 *
5
 * @author           Pierre-Henry Soria <[email protected]>
6
 * @copyright        (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved.
7
 * @license          GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
8
 * @package          PH7 / Framework / Acl
9
 * @version          0.9
10
 */
11
12
namespace PH7\Framework\Acl;
13
14
defined('PH7') or exit('Restricted access');
15
16
class AclResource
17
{
18
    /**
19
     * @param string $sName
20
     * @param string $sValue
21
     *
22
     * @throws Exception
23
     */
24
    public function __set($sName, $sValue)
25
    {
26
        switch ($sName) {
27
            case 'sName':
28
            case 'aAllowed':
29
                $this->$sName = $sValue;
30
            break;
31
32
            default:
33
                throw new Exception("Unable to set \"$sName\".");
34
        }
35
    }
36
37
    /**
38
     * @param string $sName
39
     *
40
     * @throws Exception
41
     */
42
    public function __get($sName)
43
    {
44
        switch ($sName) {
45
            case 'sName':
46
            case 'aAllowed':
47
                return $this->$sName;
48
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
49
50
            default:
51
                throw new Exception("Unable to get \"$sName\".");
52
        }
53
    }
54
55
    /**
56
     * @param string $sName
57
     *
58
     * @return bool
59
     */
60
    public function __isset($sName)
61
    {
62
        return isset($this->$sName);
63
    }
64
}
65