Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
13 / 13
Proxiable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
13 / 13
 __call
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
10 / 10
 __set
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 __get
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3namespace Amf\Proxy;
4
5trait Proxiable
6{
7    protected object $object;
8
9    /**
10     * Function calls proxy method.
11     *
12     * This function should never be called manually. Just call the original
13     * function names instead.
14     *
15     * @param string $name      The method name
16     * @param mixed[] $arguments The method arguments
17     *
18     * @return mixed The proxied method result
19     */
20    public function __call(string $name, array $arguments)
21    {
22        if (!method_exists($this->object, $name) && !method_exists($this->object, '__call')) {
23            $class = get_class($this->object);
24            $trace = debug_backtrace();
25            $file = $trace[0]['file'];
26            $line = $trace[0]['line'];
27            throw new \BadMethodCallException("Call to undefined method $class::$name() in $file on line $line");
28        }
29
30        $references = [];
31        foreach ($arguments as $i => &$arg) {
32            $references[] = &$arg;
33        }
34
35        return call_user_func_array([$this->object, $name], $arguments); // @phpstan-ignore-line
36    }
37
38    /**
39     * Property setter proxy method.
40     *
41     * This function should never be called manually. Just access the original
42     * object properties instead.
43     *
44     * @param string $name  The property name
45     * @param mixed  $value The value to set the property to
46     */
47    public function __set(string $name, $value): void
48    {
49        $this->object->$name = $value;
50    }
51
52    /**
53     * Property getter proxy method.
54     *
55     * This function should never be called manually. Just access the original
56     * object properties instead.
57     *
58     * @param string $name The property name
59     *
60     * @return mixed The proxied object property
61     */
62    public function __get(string $name)
63    {
64        return $this->object->$name;
65    }
66}