Completed
Push — master ( aa5a0d...109f75 )
by Peter
05:58
created

OwnerForwarderTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 62
wmc 6
lcom 0
cbo 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A __set() 0 4 1
A __call() 0 4 1
A __isset() 0 4 1
A __unset() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\MiniView\Traits;
10
11
/**
12
 * OwnerForwarderTrait
13
 *
14
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
15
 */
16
trait OwnerForwarderTrait
17
{
18
19
	/**
20
	 * Forward to owner
21
	 * @param string $name
22
	 * @return mixed
23
	 */
24
	public function __get($name)
25
	{
26
		return $this->getOwner()->$name;
0 ignored issues
show
Documentation Bug introduced by
The method getOwner does not exist on object<Maslosoft\MiniVie...ts\OwnerForwarderTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
	}
28
29
	/**
30
	 * Forward to owner
31
	 * @param string $name
32
	 * @param mixed $value
33
	 */
34
	public function __set($name, $value)
35
	{
36
		return $this->getOwner()->$name = $value;
0 ignored issues
show
Documentation Bug introduced by
The method getOwner does not exist on object<Maslosoft\MiniVie...ts\OwnerForwarderTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
37
	}
38
39
	/**
40
	 * Forward to owner
41
	 * @param string $name
42
	 * @param mixed[] $arguments
43
	 */
44
	public function __call($name, $arguments)
45
	{
46
		return call_user_func_array([$this->getOwner(), $name], $arguments);
0 ignored issues
show
Documentation Bug introduced by
The method getOwner does not exist on object<Maslosoft\MiniVie...ts\OwnerForwarderTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47
	}
48
49
	/**
50
	 * Forward to owner
51
	 * @param string $name
52
	 * @return bool
53
	 */
54
	public function __isset($name)
55
	{
56
		return isset($this->getOwner()->$name);
0 ignored issues
show
Documentation Bug introduced by
The method getOwner does not exist on object<Maslosoft\MiniVie...ts\OwnerForwarderTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57
	}
58
59
	/**
60
	 * Forward to owner
61
	 * @param string $name
62
	 */
63
	public function __unset($name)
64
	{
65
		unset($this->getOwner()->$name);
66
	}
67
68
	/**
69
	 * Forward __toString to owner
70
	 * @return string
71
	 */
72
	public function __toString()
73
	{
74
		return (string) $this->getOwner();
0 ignored issues
show
Documentation Bug introduced by
The method getOwner does not exist on object<Maslosoft\MiniVie...ts\OwnerForwarderTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
75
	}
76
77
}
78