These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Check that the connection to the database is working, by ensuring that the table exists and that |
||
5 | * the table contains some records. |
||
6 | */ |
||
7 | class DatabaseCheck implements EnvironmentCheck { |
||
8 | protected $checkTable; |
||
9 | |||
10 | /** |
||
11 | * By default, Member will be checked. |
||
12 | * |
||
13 | * @param string $checkTable |
||
14 | */ |
||
15 | function __construct($checkTable = "Member") { |
||
0 ignored issues
–
show
|
|||
16 | $this->checkTable = $checkTable; |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * @inheritdoc |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | function check() { |
||
0 ignored issues
–
show
|
|||
25 | if(!DB::getConn()->hasTable($this->checkTable)) { |
||
26 | return array(EnvironmentCheck::ERROR, "$this->checkTable not present in the database"); |
||
27 | } |
||
28 | |||
29 | $count = DB::query("SELECT COUNT(*) FROM \"$this->checkTable\"")->value(); |
||
30 | |||
31 | if($count > 0) { |
||
32 | return array(EnvironmentCheck::OK, ""); |
||
33 | } else { |
||
34 | return array(EnvironmentCheck::WARNING, "$this->checkTable queried ok but has no records"); |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.