This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | namespace Fwk\Events; |
||
4 | |||
5 | if(!class_exists('\Fwk\Events\Dispatcher')) |
||
0 ignored issues
–
show
|
|||
6 | require_once __DIR__ .'/../src/Dispatcher.php'; |
||
7 | |||
8 | if(!class_exists('\Fwk\Events\Event')) |
||
0 ignored issues
–
show
|
|||
9 | require_once __DIR__ .'/../src/Event.php'; |
||
10 | |||
11 | |||
12 | class MyListenerObj |
||
13 | { |
||
14 | public function onTestEvent($event) |
||
15 | { |
||
16 | $event->setProcessed(true); |
||
17 | } |
||
18 | |||
19 | public function notAListener() |
||
0 ignored issues
–
show
function notAListener() does not seem to conform to the naming convention (^(?:is|has|should|may|su...ster|unregister|exists) ).
This check examines a number of code elements and verifies that they conform to the given naming conventions. You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods. ![]() |
|||
20 | { |
||
21 | return true; |
||
22 | } |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Test class for EventDispatcher. |
||
27 | */ |
||
28 | class DispatcherTest extends \PHPUnit_Framework_TestCase { |
||
0 ignored issues
–
show
|
|||
29 | |||
30 | /** |
||
31 | * @var Dispatcher |
||
32 | */ |
||
33 | protected $object; |
||
34 | |||
35 | /** |
||
36 | * Sets up the fixture, for example, opens a network connection. |
||
37 | * This method is called before a test is executed. |
||
38 | */ |
||
39 | protected function setUp() |
||
0 ignored issues
–
show
setUp uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
40 | { |
||
41 | $this->object = new Dispatcher; |
||
42 | $GLOBALS['testEvent'] = false; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | */ |
||
47 | public function testOn() |
||
0 ignored issues
–
show
testOn uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
48 | { |
||
49 | $this->object->on('test.event', array($this, 'eventFunction')); |
||
50 | $this->object->notify(new Event('test.event')); |
||
51 | $this->assertTrue($GLOBALS['testEvent']); |
||
52 | } |
||
53 | |||
54 | // test function for event callback |
||
55 | public function eventFunction($event) |
||
0 ignored issues
–
show
eventFunction uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
56 | { |
||
57 | $GLOBALS['testEvent'] = true; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | */ |
||
62 | public function testRemoveListener() |
||
0 ignored issues
–
show
testRemoveListener uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
63 | { |
||
64 | $this->object->on('test.event', array($this, 'eventFunction')); |
||
65 | $this->object->notify(new Event('test.event')); |
||
66 | $this->assertTrue($GLOBALS['testEvent']); |
||
67 | |||
68 | $GLOBALS['testEvent'] = false; |
||
69 | $this->object->removeListener('test.event', array($this, 'eventFunction')); |
||
70 | $this->object->notify(new Event('test.event')); |
||
71 | $this->assertFalse($GLOBALS['testEvent']); |
||
72 | |||
73 | $this->assertInstanceOf('Fwk\Events\Dispatcher', $this->object->removeListener('inexistant.event', array())); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | */ |
||
78 | public function testRemoveAllListeners() |
||
0 ignored issues
–
show
testRemoveAllListeners uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
79 | { |
||
80 | $this->object->on('test.event', array($this, 'eventFunction')); |
||
81 | |||
82 | $this->object->removeAllListeners('test.event'); |
||
83 | $this->object->notify(new Event('test.event')); |
||
84 | $this->assertFalse($GLOBALS['testEvent']); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | */ |
||
89 | public function testNotify() |
||
0 ignored issues
–
show
testNotify uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
90 | { |
||
91 | $this->assertFalse($GLOBALS['testEvent']); |
||
92 | $this->object->on('test.event', array($this, 'eventFunction')); |
||
93 | |||
94 | $this->object->notify($event = new Event('test.event')); |
||
95 | $this->assertTrue($GLOBALS['testEvent']); |
||
96 | $this->assertTrue($event->isProcessed()); |
||
97 | } |
||
98 | |||
99 | public function testStoppedEvent() |
||
0 ignored issues
–
show
testStoppedEvent uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
100 | { |
||
101 | $this->assertFalse($GLOBALS['testEvent']); |
||
102 | $this->object->on('test.event', function(Event $event) { |
||
103 | $event->stop(); |
||
104 | }); |
||
105 | $this->object->on('test.event', array($this, 'eventFunction')); |
||
106 | $this->object->notify('test.event'); |
||
107 | $this->assertFalse($GLOBALS['testEvent']); // event was stopped |
||
108 | } |
||
109 | |||
110 | public function testListenerObject() |
||
111 | { |
||
112 | $this->object->addListener(new MyListenerObj()); |
||
113 | $this->object->notify($event = new Event('testEvent')); |
||
114 | $this->assertTrue($event->isProcessed()); |
||
115 | } |
||
116 | |||
117 | public function testInvalidListenerObject() |
||
118 | { |
||
119 | $this->setExpectedException('\InvalidArgumentException'); |
||
120 | $this->object->addListener(function($event) { return false; }); |
||
121 | } |
||
122 | } |
||
123 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.