Completed
Push — test ( 5bf343...41c779 )
by Temitope
03:44
created

DatabaseHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createTable() 0 13 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 Laztopaz\PotatoORM\TableNotCreatedException;
12
13
class DatabaseHelper {
14
  
15
    public $dbConn;
16
    
17
    /**
18
     * This is a constructor; a default method  that will be called automatically during class instantiation
19
     */
20
    public function __construct($dbConnect)
21
    {
22
        $this->dbConn = $dbConnect;
23
        
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
            $conn = $this->dbConn;
35
        }
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::create("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