Test Failed
Push — master ( 9006a4...ddf4bb )
by Nuno
02:36
created

ContainerProxyTrait::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
/**
4
 * This file is part of Zero Framework.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\ZeroFramework;
13
14
use BadMethodCallException;
15
16
/**
17
 * The is the Zero Framework container proxy class.
18
 *
19
 * @author Nuno Maduro <[email protected]>
20
 */
21
trait ContainerProxyTrait
22
{
23
    /**
24
     * Proxies calls into the container.
25
     *
26
     * @param string $method
27
     * @param array $parameters
28
     *
29
     * @throws \BadMethodCallException
30
     *
31
     * @return mixed
32
     */
33
    public function __call(string $method, array $parameters)
34
    {
35
        if (is_callable([$this->container, $method])) {
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36
            return call_user_func_array([$this->container, $method], $parameters);
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37
        }
38
39
        throw new BadMethodCallException("Method [{$method}] does not exist.");
40
    }
41
42
    /**
43
     * Dynamically access container services.
44
     *
45
     * @param string $key
46
     *
47
     * @return mixed
48
     */
49
    public function __get(string $key)
50
    {
51
        return $this->container->{$key};
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
    }
53
54
    /**
55
     * Dynamically set container services.
56
     *
57
     * @param string $key
58
     * @param mixed $value
59
     *
60
     * @return void
61
     */
62
    public function __set(string $key, $value): void
63
    {
64
        $this->container->{$key} = $value;
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
    }
66
67
    /**
68
     * Determine if a given offset exists.
69
     *
70
     * @param string $key
71
     *
72
     * @return bool
73
     */
74
    public function offsetExists($key): bool
75
    {
76
        return isset($this->container[$key]);
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
77
    }
78
79
    /**
80
     * Get the value at a given offset.
81
     *
82
     * @param string $key
83
     *
84
     * @return mixed
85
     */
86
    public function offsetGet($key)
87
    {
88
        return $this->container[$key];
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
89
    }
90
91
    /**
92
     * Set the value at a given offset.
93
     *
94
     * @param string $key
95
     * @param mixed $value
96
     *
97
     * @return void
98
     */
99
    public function offsetSet($key, $value): void
100
    {
101
        $this->container[$key] = $value;
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<NunoMaduro\ZeroFr...rk\ContainerProxyTrait>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
102
    }
103
104
    /**
105
     * Unset the value at a given offset.
106
     *
107
     * @param string $key
108
     *
109
     * @return void
110
     */
111
    public function offsetUnset($key): void
112
    {
113
        unset($this->container[$key]);
114
    }
115
}
116