Skip to content

Commit 430adc1

Browse files
committed
added phpstan to build and applied level 1 fixes
1 parent 66b2b92 commit 430adc1

33 files changed

+234
-163
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ after_success:
3030

3131
# Commands you want to run that will verify your build.
3232
script:
33-
- phpunit --coverage-clover=coverage.xml
33+
- vendor/bin/phpunit --coverage-clover=coverage.xml
34+
- vendor/bin/phpstan analyse lib tests --level=1
3435

3536
# allow_failures: Allow this build to fail under the specified environments.
3637
# fast_finish: If your build fails do not continue trying to build, just stop.

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ on_success:
111111
## Run the actual test
112112
test_script:
113113
- cd c:\projects\php-project-workspace
114-
- vendor/bin/phpunit --coverage-clover=coverage.xml
114+
- vendor\bin\phpunit --coverage-clover=coverage.xml
115+
- vendor\bin\phpstan analyse lib tests --level=1
115116

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
}
3838
},
3939
"require-dev": {
40-
"phpunit/phpunit": ">5.7.0"
40+
"phpunit/phpunit": ">5.7.0",
41+
"phpstan/phpstan": "^0.11.5"
4142
},
4243
"autoload-dev": {
4344
"psr-4": {

lib/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @method void setCharset($args);
1919
* @method void setOptions($args);
2020
* @method void setIsFile($args);
21-
* @method void setToMysql($args);
21+
* @method void setToMssql($args);
2222
* @method void setPath($args);
2323
*
2424
* @method string getDriver();
@@ -31,7 +31,7 @@
3131
* @method string getCharset();
3232
* @method string getOptions();
3333
* @method bool getIsFile();
34-
* @method bool getToMysql();
34+
* @method bool getToMssql();
3535
* @method string getPath();
3636
*/
3737
class Config extends ConfigAbstract implements ConfigInterface

lib/Database/ez_mysqli.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
2323
5 => 'Unexpected error while trying to select database'
2424
);
2525

26-
protected $preparedValues = array();
27-
2826
private static $isSecure = false;
2927
private static $secure = null;
3028

3129
/**
3230
* Database connection handle
33-
* @var connection instance
31+
* @var resource
3432
*/
3533
private $dbh;
3634

@@ -42,7 +40,7 @@ class ez_mysqli extends ezsqlModel implements DatabaseInterface
4240

4341
/**
4442
* Database configuration setting
45-
* @var Configuration instance
43+
* @var ConfigInterface
4644
*/
4745
private $database;
4846

@@ -222,9 +220,9 @@ public function sysDate() {
222220

223221
/**
224222
* Helper fetches rows from a prepared result set
225-
* @param mysqli_stmt $stmt
223+
* @param \mysqli_stmt $stmt
226224
* @param string $query
227-
* @return bool|mysqli_result
225+
* @return bool|\mysqli_result
228226
*/
229227
private function fetch_prepared_result(&$stmt, $query)
230228
{
@@ -291,7 +289,7 @@ private function fetch_prepared_result(&$stmt, $query)
291289
* {@link mysqli_stmt}.
292290
* @param string $query
293291
* @param array $param
294-
* @return bool|mysqli_result
292+
* @return bool|\mysqli_result
295293
*/
296294
public function query_prepared(string $query, array $param = null)
297295
{

lib/Database/ez_pdo.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface
2121
2 => 'File based databases require $dsn to create a connection'
2222
);
2323

24-
protected $preparedValues = array();
25-
2624
private static $isSecure = false;
2725
private static $secure = null;
2826
private static $_options = [];
2927

3028
/**
3129
* Database connection handle
32-
* @var connection instance
30+
* @var resource
3331
*/
3432
private $dbh;
3533

@@ -41,7 +39,7 @@ class ez_pdo extends ezsqlModel implements DatabaseInterface
4139

4240
/**
4341
* Database configuration setting
44-
* @var Configuration instance
42+
* @var ConfigInterface
4543
*/
4644

4745
private $database;
@@ -168,7 +166,6 @@ public function connect(
168166
$this->register_error($e->getMessage());
169167
$this->show_errors ? \trigger_error($e->getMessage() . '- $dsn: ' . $dsn, \E_USER_WARNING) : null;
170168
}
171-
$this->isConnected = $this->_connected;
172169

173170
return $this->_connected;
174171
} // connect
@@ -274,7 +271,7 @@ public function catch_error()
274271
* @param string $query
275272
* @param array $param
276273
* @param boolean $isSelect - return \PDOStatement, if SELECT SQL statement, otherwise int
277-
* @return bool|int|PDOStatement
274+
* @return bool|int|\PDOStatement
278275
*/
279276
public function query_prepared(string $query, array $param = null, $isSelect = false)
280277
{

lib/Database/ez_pgsql.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class ez_pgsql extends ezsqlModel implements DatabaseInterface
2222
5 => 'Unexpected error while trying to select database',
2323
);
2424

25-
protected $preparedValues = array();
26-
2725
private static $isSecure = false;
2826
private static $secure = null;
2927

3028
/**
3129
* Database connection handle
32-
* @var connection instance
30+
* @var resource
3331
*/
3432
private $dbh;
3533

@@ -41,7 +39,7 @@ class ez_pgsql extends ezsqlModel implements DatabaseInterface
4139

4240
/**
4341
* Database configuration setting
44-
* @var Configuration instance
42+
* @var ConfigInterface
4543
*/
4644
private $database;
4745

@@ -85,7 +83,7 @@ public function settings()
8583
*/
8684
public function quick_connect($user = '', $password = '', $name = '', $host = 'localhost', $port = '5432')
8785
{
88-
if (!$this->connect($user, $password, $name, $host, $port, true));
86+
if (!$this->connect($user, $password, $name, $host, $port));
8987
return $this->_connected;
9088
} // quick_connect
9189

lib/Database/ez_sqlite3.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface
1616
private $ezsql_sqlite3_str = array
1717
(
1818
1 => 'Require $path and $name to open an SQLite database',
19+
2 => 'Failed to make connection to database',
1920
);
2021

21-
protected $preparedValues = array();
22-
2322
/**
2423
* Database connection handle
25-
* @var connection instance
24+
* @var resource
2625
*/
2726
private $dbh;
2827

@@ -34,7 +33,7 @@ class ez_sqlite3 extends ezsqlModel implements DatabaseInterface
3433

3534
/**
3635
* Database configuration setting
37-
* @var Configuration instance
36+
* @var ConfigInterface
3837
*/
3938
private $database;
4039

@@ -86,8 +85,8 @@ public function connect($path = '', $name = '')
8685
$this->show_errors ? \trigger_error($this->ezsql_sqlite3_str[1], \E_USER_WARNING) : null;
8786
// Try to establish the server database handle
8887
} elseif (!$this->dbh = @new \SQLite3($path . $name)) {
89-
$this->register_error($php_errormsg);
90-
$this->show_errors ? \trigger_error($php_errormsg, \E_USER_WARNING) : null;
88+
$this->register_error($this->ezsql_sqlite3_str[2]);
89+
$this->show_errors ? \trigger_error($this->ezsql_sqlite3_str[2], \E_USER_WARNING) : null;
9190
} else {
9291
$return_val = true;
9392
$this->conn_queries = 0;
@@ -200,7 +199,7 @@ public function query(string $query, bool $use_prepare = false)
200199
$this->flush();
201200

202201
// Log how the function was called
203-
$this->func_call = "\$db->query(\"$query\")";
202+
$this->log_query("\$db->query(\"$query\")");
204203

205204
// Keep track of the last query for debug..
206205
$this->last_query = $query;
@@ -245,7 +244,7 @@ public function query(string $query, bool $use_prepare = false)
245244
$i = 0;
246245
$this->col_info = array();
247246
while ($i < @$this->result->numColumns()) {
248-
$this->col_info[$i] = new \StdClass;
247+
$this->col_info[$i] = new \stdClass;
249248
$this->col_info[$i]->name = $this->result->columnName($i);
250249
$this->col_info[$i]->type = null;
251250
$this->col_info[$i]->max_length = null;

lib/Database/ez_sqlsrv.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ class ez_sqlsrv extends ezsqlModel implements DatabaseInterface
3232
-11 => 'uniqueidentifier', -3 => 'varbinary', 12 => 'varchar', -152 => 'xml',
3333
);
3434

35-
protected $preparedValues = array();
36-
3735
private static $isSecure = false;
3836

3937
/**
4038
* Database connection handle
41-
* @var connection instance
39+
* @var resource
4240
*/
4341
private $dbh;
4442

@@ -50,7 +48,7 @@ class ez_sqlsrv extends ezsqlModel implements DatabaseInterface
5048

5149
/**
5250
* Database configuration setting
53-
* @var Configuration instance
51+
* @var ConfigInterface
5452
*/
5553
private $database;
5654

@@ -258,6 +256,7 @@ public function query(string $query, bool $use_prepare = false)
258256
// Take note of column info
259257
$i = 0;
260258
foreach (@\sqlsrv_field_metadata($this->result) as $field) {
259+
$col = [];
261260
foreach ($field as $name => $value) {
262261
$name = \strtolower($name);
263262
if ($name == "size") {
@@ -267,7 +266,7 @@ public function query(string $query, bool $use_prepare = false)
267266
}
268267

269268
//DEFINED FOR E_STRICT
270-
$col = new \StdClass();
269+
$col = new \stdClass();
271270
$col->{$name} = $value;
272271
}
273272

lib/DatabaseInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function sysDate();
6666
*
6767
* @param string $query
6868
* @param array $param
69-
* @return bool|result
69+
* @return bool|mixed
7070
*/
7171
public function query_prepared(string $query, array $param = null);
7272

0 commit comments

Comments
 (0)