Completed
Push — 4.0 ( b7ae43...1bebd1 )
by Marco
16:17
created

ServiceEvent::extra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Comodojo\Dispatcher\Events;
2
3
use \Comodojo\Events\AbstractEvent;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Comodojo\Dispatcher\Events\AbstractEvent.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use \Comodojo\Dispatcher\Request\Model as Request;
5
use \Comodojo\Dispatcher\Router\Collector as Router;
6
use \Comodojo\Dispatcher\Response\Model as Response;
7
use \Comodojo\Dispatcher\Extra\Model as Extra;
8
use \Monolog\Logger;
9
10
class ServiceEvent extends AbstractEvent {
11
12
    private $logger;
13
14
    private $request;
15
16
    private $router;
17
18
    private $response;
19
    
20
    private $extra;
21
22
    public function __construct(
23
        $name,
24
        Logger $logger,
25
        Request $request,
26
        Router $router,
27
        Response $response,
28
        Extra $extra
29
    ) {
30
31
        parent::__construct($name);
32
33
        $this->logger = $logger;
34
35
        $this->request = $request;
36
37
        $this->router = $router;
38
39
        $this->response = $response;
40
        
41
        $this->extra = $extra;
42
43
    }
44
45
    final public function logger() {
46
47
        return $this->logger;
48
49
    }
50
51
    final public function request() {
52
53
        return $this->request;
54
55
    }
56
57
    final public function router() {
58
59
        return $this->router;
60
61
    }
62
63
    final public function response() {
64
65
        return $this->response;
66
67
    }
68
    
69
    final public function extra() {
70
71
        return $this->extra;
72
73
    }
74
75
}
76