Test Failed
Push — trunk ( db071f...8d464a )
by SuperNova.WS
06:33
created

Schema   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A clear() 0 4 1
A loadTableNamesFromDb() 0 20 4
A getAllTables() 0 7 2
A getSnTables() 0 7 2
A isSnTableExists() 0 3 1
1
<?php
2
/**
3
 * Created by Gorlum 12.06.2017 15:29
4
 */
5
6
namespace DBAL;
7
8
9
class Schema {
10
11
  /**
12
   * @var \db_mysql $db
13
   */
14
  protected $db;
15
16
  /**
17
   * List of all table names
18
   *
19
   * @var string[] $tablesAll
20
   */
21
  protected $tablesAll = null;
22
  /**
23
   * @var string[] $tablesSn
24
   */
25
  protected $tablesSn = null;
26
27
28
  public function __construct(\db_mysql $db) {
29
    $this->db = $db;
30
  }
31
32
  public function clear() {
33
    $this->tablesAll = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array<integer,string> of property $tablesAll.

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...
34
    $this->tablesSn = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array<integer,string> of property $tablesSn.

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...
35
  }
36
37
  protected function loadTableNamesFromDb() {
38
    $this->clear();
39
    $this->tablesAll = array();
40
    $this->tablesSn = array();
41
42
    $query = $this->db->mysql_get_table_list();
43
44
    $prefix_length = strlen($this->db->db_prefix);
45
46
    while($row = $this->db->db_fetch($query)) {
47
      foreach($row as $table_name) {
48
        $this->tablesAll[$table_name] = $table_name;
49
50
        if(strpos($table_name, $this->db->db_prefix) === 0) {
51
          $table_name_sn = substr($table_name, $prefix_length);
52
          $this->tablesSn[$table_name_sn] = $table_name_sn;
53
        }
54
      }
55
    }
56
  }
57
58
  /**
59
   * Get names of all tables in this DB
60
   *
61
   * @return \string[]
62
   */
63
  public function getAllTables() {
64
    if(!isset($this->tablesAll)) {
65
      $this->loadTableNamesFromDb();
66
    }
67
68
    return $this->tablesAll;
69
  }
70
71
  /**
72
   * Get un-prefixed table names potentially used by game
73
   *
74
   * @return string[]
75
   */
76
  public function getSnTables() {
77
    if(!isset($this->tablesSn)) {
78
      $this->loadTableNamesFromDb();
79
    }
80
81
    return $this->tablesSn;
82
  }
83
84
  /**
85
   * Checks if SN table exists
86
   *
87
   * @param $tableName
88
   *
89
   * @return bool
90
   */
91
  public function isSnTableExists($tableName) {
92
    return isset($this->getSnTables()[$tableName]);
93
  }
94
95
}
96