Event   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 69.23%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
cbo 1
dl 0
loc 65
ccs 9
cts 13
cp 0.6923
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setReturnValue() 0 4 1
A getReturnValue() 0 4 1
A hasReturnValue() 0 4 1
A getContainer() 0 4 1
A __construct() 0 11 1
1
<?php
2
/**
3
 * Fwk
4
 *
5
 * Copyright (c) 2011-2015, Julien Ballestracci <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
15
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
21
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 * POSSIBILITY OF SUCH DAMAGE.
23
 *
24
 * PHP Version 5.3
25
 *
26
 * @category  Dependency Injection
27
 * @package   Fwk\Di
28
 * @author    Julien Ballestracci <[email protected]>
29
 * @copyright 2011-2015 Julien Ballestracci <[email protected]>
30
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
31
 * @link      http://www.phpfwk.com
32
 */
33
namespace Fwk\Di;
34
35
use Fwk\Events\Event as BaseEvent;
36
37
/**
38
 * @category Listeners
39
 * @package  Fwk\Di
40
 * @author   Julien Ballestracci <[email protected]>
41
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link     http://www.phpfwk.com
43
 */
44
class Event extends BaseEvent
45
{
46
    /**
47
     * Constructor
48
     *
49
     * @param string    $name
50
     * @param array     $data
51
     * @param Container $container
0 ignored issues
show
Documentation introduced by
Should the type for parameter $container not be null|Container?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
52
     *
53
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
54
     */
55 39
    public function __construct($name, $data = array(), Container $container = null)
56
    {
57 39
        parent::__construct(
58
            $name, array_merge(
59
                $data, array(
60 39
                'container'       => $container,
61
                'returnValue'     => null
62
                )
63
            )
64
        );
65 39
    }
66
67
    /**
68
     * Defines a returnValue which can be used to override standard return values by functions handling this event.
69
     *
70
     * @param mixed $value
71
     *
72
     * @return void
73
     */
74 1
    public function setReturnValue($value)
75
    {
76 1
        $this->returnValue = $value;
0 ignored issues
show
Documentation introduced by
The property returnValue does not exist on object<Fwk\Di\Event>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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 1
    }
78
79
    /**
80
     * Returns the "returnValue" if defined
81
     *
82
     * @return mixed
83
     */
84 1
    public function getReturnValue()
85
    {
86 1
        return $this->returnValue;
0 ignored issues
show
Documentation introduced by
The property returnValue does not exist on object<Fwk\Di\Event>. 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...
87
    }
88
89
    /**
90
     * Tells if the event has a return value defined
91
     *
92
     * @return boolean
93
     */
94
    public function hasReturnValue()
95
    {
96
        return isset($this->returnValue);
97
    }
98
99
    /**
100
     * Returns the Dependency Injection Container
101
     *
102
     * @return Container
103
     */
104
    public function getContainer()
105
    {
106
        return $this->container;
0 ignored issues
show
Documentation introduced by
The property container does not exist on object<Fwk\Di\Event>. 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...
107
    }
108
}