OwnerForwarderTrait::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/miniview
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 * @link http://maslosoft.com/miniview/
12
 */
13
14
namespace Maslosoft\MiniView\Traits;
15
16
/**
17
 * OwnerForwarderTrait
18
 *
19
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
20
 */
21
trait OwnerForwarderTrait
22
{
23
24
	/**
25
	 * Forward to owner
26
	 * @param string $name
27
	 * @return mixed
28
	 */
29
	public function __get($name)
30
	{
31
		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...
32
	}
33
34
	/**
35
	 * Forward to owner
36
	 * @param string $name
37
	 * @param mixed $value
38
	 */
39
	public function __set($name, $value)
40
	{
41
		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...
42
	}
43
44
	/**
45
	 * Forward to owner
46
	 * @param string $name
47
	 * @param mixed[] $arguments
48
	 */
49
	public function __call($name, $arguments)
50
	{
51
		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...
52
	}
53
54
	/**
55
	 * Forward to owner
56
	 * @param string $name
57
	 * @return bool
58
	 */
59
	public function __isset($name)
60
	{
61
		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...
62
	}
63
64
	/**
65
	 * Forward to owner
66
	 * @param string $name
67
	 */
68
	public function __unset($name)
69
	{
70
		unset($this->getOwner()->$name);
71
	}
72
73
	/**
74
	 * Forward __toString to owner
75
	 * @return string
76
	 */
77
	public function __toString()
78
	{
79
		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...
80
	}
81
82
}
83