Resource   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setAttributes() 0 6 2
A setAttribute() 0 8 2
A hasAttribute() 0 4 1
A getAttribute() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[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 Bouncer;
13
14
class Resource
15
{
16
17
    protected $attributes = array();
18
19
    public function __construct($attributes = null)
20
    {
21
        if (!empty($attributes)) {
22
            $this->setAttributes($attributes);
23
        }
24
    }
25
26
    public function setAttributes($attributes = array())
27
    {
28
        foreach ($attributes as $key => $value) {
29
            $this->setAttribute($key, $value);
30
        }
31
    }
32
33
    public function setAttribute($key, $value)
34
    {
35
        $this->attributes[$key] = $value;
36
        $setMethod = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
37
        if (method_exists($this, $setMethod)) {
38
            $this->$setMethod($value);
39
        }
40
    }
41
42
    public function hasAttribute($key)
43
    {
44
        return array_key_exists($key, $this->attributes);
45
    }
46
47
    public function getAttribute($name)
48
    {
49
        if (isset($this->attributes[$name])) {
50
            return $this->attributes[$name];
51
        }
52
    }
53
54
}
55