Completed
Push — 4.0 ( 38d142...8ab097 )
by Marco
03:25
created

DataAccess::__get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php namespace Comodojo\Dispatcher\Components;
2
3
/**
4
 * @package     Comodojo Dispatcher
5
 * @author      Marco Giovinazzi <[email protected]>
6
 * @author      Marco Castiello <[email protected]>
7
 * @license     GPL-3.0+
8
 *
9
 * LICENSE:
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
26
trait DataAccess {
27
    
28
    protected $data = array();
29
30 12
    public function __get($name) {
31
        
32 12
        if ( array_key_exists($name, $this->data) ) {
33
            
34 12
            return $this->data[$name];
35
            
36
        }
37
        
38 1
        return null;
39
        
40
        // $className = get_class($this);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
        
42
        // throw new Exception("Invalid property $name for $className");
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
        
44
    }
45
    
46 6
    public function __set($name, $value) {
47
        
48
        // $className = get_class($this);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
        
50
        // if ( array_key_exists($name, $this->data) === false ) throw new Exception("Invalid property $name for $className");
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        
52 6
        $this->data[$name] = $value;
53
        
54 6
    }
55
    
56 1
    public function __isset($name) {
57
        
58 1
        return array_key_exists($name, $this->data);
59
        
60
    }
61
    
62
    public function merge($data) {
63
64
        foreach ($data as $key => $value) {
65
            $this->$key = $value;
66
        }
67
68
        return $this;
69
70
    }
71
    
72
    public function export() {
73
        
74
        return $this->data;
75
        
76
    }
77
    
78
    public function import($data) {
79
        
80
        $this->data = $data;
81
        
82
        return $this;
83
        
84
    }
85
86
}
87