Completed
Branch master (a17b64)
by Rémi
15:50
created

MagicGetters::__isset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Analogue\ORM;
4
5
trait MagicGetters
6
{
7
	/**
8
	 * Contains the entity's attributes
9
	 * 
10
	 * @var array
11
	 */
12
	protected $attributes = [];
13
14
	/**
15
     * Dynamically retrieve attributes on the entity.
16
     *
17
     * @param  string $key
18
     * @return mixed
19
     */
20
    public function __get($key)
21
    {
22
    	// When using mixed mapping, we will check
23
    	// for a class property corresponding to 
24
    	// the attribute's key first. 
25
    	// 
26
    	// Note : this may raise issues as we may grant
27
    	// access to unwanted properties, like class dependencies. 
28
    	// 
29
    	// -> Solution would be to access the entityMap's $attributes, but we
30
    	// have to do this in a very efficient way.
31
    	// 
32
    	// Manager::getEntityMap(get_class($this))->hasProperty()
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
33
    	// 
34
    	// We could do the casting to array / json the same way, and it would 
35
    	
36
37
    	if(property_exists($this, $key)) {
38
    		return $this->$key;
39
    	}
40
41
    	if(array_key_exists($key, $this->attributes))
42
    	{
43
        	return $this->attributes[$key];
44
        }
45
46
        return null;
47
    }
48
49
    /**
50
     * Determine if an attribute exists on the entity.
51
     *
52
     * @param  string $key
53
     * @return bool
54
     */
55
    public function __isset($key)
56
    {
57
        return array_key_exists($key, $this->attributes) || property_exists($this, $key);
58
    }
59
}