ErrorEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
namespace Fwk\Core\Events;
3
4
use Fwk\Core\Application;
5
use Fwk\Core\Context;
6
use Fwk\Core\CoreEvent;
7
use Fwk\Core\AppEvents;
8
9
/**
10
 * This event is notified when an exception occurs while the application is
11
 * running. {@see Application::run()}
12
 * 
13
 * If you wish to prevent the exception to be thrown, you have to stop the event
14
 * using  $event->stop()
15
 */
16
class ErrorEvent extends CoreEvent
17
{
18
    /**
19
     * Constructor
20
     * 
21
     * @param \Exception  $exception
22
     * @param Application $app
23
     * @param Context     $context 
0 ignored issues
show
Documentation introduced by
Should the type for parameter $context not be null|Context?

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...
24
     * 
25
     * @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...
26
     */
27 3
    public function __construct(\Exception $exception, Application $app, 
28
        Context $context = null
29
    ) {
30 3
        parent::__construct(
31 3
            AppEvents::ERROR, 
32 3
            array('exception'  =>  $exception), 
33 3
            $app, 
34
            $context
35 3
        );
36 3
    }
37
    
38
    /**
39
     * Gets the Exception
40
     * 
41
     * @return \Exception
42
     */
43
    public function getException()
44
    {
45
        return $this->exception;
0 ignored issues
show
Documentation introduced by
The property exception does not exist on object<Fwk\Core\Events\ErrorEvent>. 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...
46
    }
47
}