Completed
Push — test ( dd676d...2ee69c )
by Temitope
02:42
created

DatabaseHelper::getColumnNames()   B

Complexity

Conditions 4
Paths 17

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 30
rs 8.5806
cc 4
eloc 15
nc 17
nop 2
1
<?php
2
3
/**
4
 * @package  Laztopaz\potato-ORM
5
 * @author   Temitope Olotin <[email protected]>
6
 * @license  <https://opensource.org/license/MIT> MIT
7
 */
8
9
namespace Laztopaz\potatoORM;
10
11
use PDO;
12
use Laztopaz\potatoORM\TableNotCreatedException;
13
14
class DatabaseHelper {
15
16
	public $dbConn;
17
18
	/**
19
	 * This is a constructor; a default method  that will be called automatically during class instantiation
20
	 */
21
	public function __construct($dbConnect)
22
	{
23
		$this->dbConn = $dbConnect;
24
	}
25
26
	/**
27
	 * This method creates a particular table
28
	 * @param tableName
29
	 * $return boolean true or false
30
	 */
31
	public function createTable($tableName, $conn = NULL)
32
	{
33
		if (is_null($conn)) {
34
35
			$conn = $this->dbConn;
36
		}
37
		$sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'(';
38
		$sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )';
39
40
		return $conn->exec($sql);
41
42
		throw TableNotCreatedException::tableNotCreatedException("Check your database connection");
0 ignored issues
show
Unused Code introduced by
throw \Laztopaz\potatoOR... database connection'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
43
44
	}
45
46
}