Issues (180)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/ConnectionEventsTest.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Fwk\Db;
4
use Fwk\Db\Events\AfterQueryEvent;
5
use Fwk\Db\Events\BeforeQueryEvent;
6
use Fwk\Db\Events\ConnectEvent;
7
use Fwk\Db\Events\ConnectionErrorEvent;
8
use Fwk\Db\Events\ConnectionStateChangeEvent;
9
use Fwk\Db\Events\DisconnectEvent;
10
use Fwk\Db\Exceptions\ConnectionErrorException;
11
12
13
class TestConnectionListener
14
{
15
    public $disconnected = true;
16
    public $hasErrored = false;
17
    public $states = 0;
18
    public $currentState;
19
20
    public $currentQuery;
21
    public $currentQueryParams;
22
    public $currentQueryOpts;
23
    public $currentQueryResults;
24
25
    public $queries = 0;
26
27
    public function onConnect(ConnectEvent $event)
28
    {
29
        $this->currentState = $event->getConnection()->getState();
30
        $this->disconnected = false;
31
    }
32
33
    public function onDisconnect(DisconnectEvent $event)
34
    {
35
        $this->disconnected = true;
36
    }
37
38
    public function onConnectionError(ConnectionErrorEvent $event)
39
    {
40
        $this->hasErrored = $event->getException();
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->getException() of type object<Exception> is incompatible with the declared type boolean of property $hasErrored.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        if($event->getConnection()->isConnected()) {
42
            $event->getConnection()->disconnect();
43
        }
44
    }
45
46
    public function onConnectionStateChange(ConnectionStateChangeEvent $event)
47
    {
48
        if ($event->getNewState() != $event->getPreviousState()) {
49
            $this->states++;
50
        }
51
        $this->currentState = $event->getConnection()->getState();
52
    }
53
54
    public function onBeforeQuery(BeforeQueryEvent $event)
55
    {
56
        $opts = $event->getQueryOptions();
57
        $event->setQueryOptions($opts + array('testopt' => true));
58
        $results = $event->getResults();
0 ignored issues
show
$results is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
60
        if (!isset($this->currentQueryResults)) {
61
            $this->currentQuery = $event->getQuery();
62
            $this->currentQueryParams = $event->getQueryParameters();
63
            $this->currentQueryOpts = $event->getQueryOptions();
64
65
            $event->setResults(666);
66
            $event->stop();
67
            $this->currentQueryResults = true;
68
        } else {
69
            $event->setQuery(Query::factory());
70
            $event->setQueryParameters(array('driver_opt' => 'one'));
71
            $event->setResults(null);
72
        }
73
    }
74
75
    public function onAfterQuery(AfterQueryEvent $event)
76
    {
77
        $this->queries++;
78
        $this->currentQueryResults = $event->getResults();
79
        $this->currentState = $event->getConnection()->getState();
80
    }
81
}
82
/**
83
 * Test class for EventDispatcher.
84
 */
85
class ConnectionEventsTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
86
{
87
    /**
88
     * @var Connection
89
     */
90
    protected $object;
91
    protected $listener;
92
    protected $listener2;
93
94
    /**
95
     * Sets up the fixture, for example, opens a network connection.
96
     * This method is called before a test is executed.
97
     */
98
    protected function setUp()
99
    {
100
        $this->object = new Connection(array(
101
            'memory'    => true,
102
            'driver'    => 'pdo_sqlite'
103
        ));
104
105
        $this->object->addListener($this->listener = new TestConnectionListener());
106
107
        \FwkDbTestUtil::createTestDb($this->object);
108
    }
109
110
    protected function tearDown()
111
    {
112
        try {
113
            \FwkDbTestUtil::dropTestDb($this->object);
114
        } catch(ConnectionErrorException $exp) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
115
        }
116
    }
117
118
    public function testConnectAndDisconnectEvents()
119
    {
120
        $this->assertFalse($this->listener->disconnected);
121
    }
122
123
    public function testConnectionErrorEvent()
124
    {
125
        $this->object = new Connection(array(
126
            'driver'    => 'pdo_mysql',
127
            'host'  => 'inexistant.example.com-no',
128
            'user'  => 'testEUH',
129
            'autoConnect' => false
130
        ));
131
132
        $this->object->addListener($this->listener = new TestConnectionListener());
133
134
        $this->assertFalse($this->object->isConnected());
135
        $this->assertFalse($this->listener->hasErrored);
136
137
        $this->setExpectedException('\Fwk\Db\Exceptions\ConnectionErrorException');
138
        $this->object->connect();
139
140
        $this->assertTrue(($this->listener->hasErrored instanceof Exception));
141
    }
142
143
    public function testConnectionStateChangeEvent()
144
    {
145
        $connx = new Connection(array(
146
            'driver'    => 'pdo_mysql',
147
            'host'  => 'inexistant.example.com-no',
148
            'user'  => 'testEUH',
149
            'autoConnect' => false
150
        ));
151
152
        $connx->addListener($this->listener2 = new TestConnectionListener());
153
154
        $this->assertEquals(0, $this->listener2->states);
155
        $this->setExpectedException('\Fwk\Db\Exceptions\ConnectionErrorException');
156
        $connx->connect();
157
158
        $this->assertEquals(2 /* connect + error */, $this->listener2->states);
159
    }
160
161
    public function testBeforeAndAfterQueryEvents()
162
    {
163
        $query = Query::factory()
164
            ->insert('fwkdb_test_users')
165
            ->set('username', 'joeBar');
166
167
        $this->object->execute($query);
168
        $this->assertEquals(0, $this->listener->queries); // should have been stopped
169
170
        $query2 = Query::factory()
171
            ->insert('fwkdb_test_users')
172
            ->set('username', 'joeBar');
173
174
        $this->object->execute($query2);
175
        $this->assertEquals(1, $this->listener->queries);
176
    }
177
}
178