Completed
Push — 2.0 ( bddf1c )
by Vermeulen
02:18
created

Modeles   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 27 5
1
<?php
2
3
namespace BfwSql;
4
5
use \Exception;
6
7
/**
8
 * Abstract class for all Models class
9
 * 
10
 * @package bfw-sql
11
 * @author Vermeulen Maxime <[email protected]>
12
 * @version 2.0
13
 */
14
abstract class Modeles extends \BFWSql\Sql
15
{
16
    /**
17
     * @var $tableName The table name
18
     */
19
    protected $tableName = '';
20
    
21
    /**
22
     * @var $tableNameWithPrefix the table name with prefix
23
     */
24
    protected $tableNameWithPrefix = '';
25
    
26
    /**
27
     * @var $baseKeyName The baseKeyName to use to connection.
28
     *  Use it if they are multiple database to connect in the application.
29
     */
30
    protected $baseKeyName = '';
31
    
32
    /**
33
     * Constructor
34
     */
35
    public function __construct()
36
    {
37
        $app       = \BFW\Application::getInstance();
38
        $listBases = $app->getModule('bfw-sql')->listBases;
39
        
40
        if (
41
            count($listBases) > 1
42
            && (
43
                empty($this->baseKeyName)
44
                || !isset($listBases[$this->baseKeyName])
45
            )
46
        ) {
47
            throw new Exception(
48
                'They are multiple connection, '
49
                .'so the property baseKeyName must be defined'
50
            );
51
        }
52
        
53
        if (count($listBases) === 1) {
54
            $sqlConnect = current($listBases);
55
        } else {
56
            $sqlConnect = $listBases[$this->baseKeyName];
57
        }
58
        
59
        parent::__construct($sqlConnect);
60
        $this->tableNameWithPrefix = $this->prefix.$this->tableName;
61
    }
62
}
63