SizeOfDatabase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCalculatedAnswer() 0 13 4
1
<?php
2
3
namespace Sunnysideup\HealthCheckProvider\Checks\Database;
4
5
use SilverStripe\ORM\DB;
6
use Sunnysideup\HealthCheckProvider\Checks\HealthCheckItemRunner;
7
8
class SizeOfDatabase extends HealthCheckItemRunner
9
{
10
    private static $fields_required = [
0 ignored issues
show
introduced by
The private property $fields_required is not used, and could be removed.
Loading history...
11
        'Name',
12
        'Engine',
13
        'Data_length',
14
        'Index_length',
15
        'Collation',
16
    ];
17
18
    public function getCalculatedAnswer(): array
19
    {
20
        $rows = DB::query('SHOW TABLE STATUS;');
21
        $allowedKeys = $this->Config()->get('fields_required');
22
        $array = $rows;
23
        foreach ($array as $pos => $row) {
24
            foreach (array_keys($row) as $key) {
25
                if (! in_array($key, $allowedKeys, true)) {
26
                    unset($array[$pos][$key]);
27
                }
28
            }
29
        }
30
        return $array;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $array returns the type SilverStripe\ORM\Connect\Query which is incompatible with the type-hinted return array.
Loading history...
31
    }
32
}
33