StatisticsController   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 4
dl 0
loc 92
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A statisticsAction() 0 15 1
A setReleaseDate() 0 16 3
A setHostingData() 0 20 2
A loadConfiguration() 0 9 4
A setPanelData() 0 15 2
A getPublicPath() 0 9 4
1
<?php
2
3
namespace ExpressApi\V1\Rpc\Statistics;
4
5
use Zend\Mvc\Controller\AbstractActionController;
6
use \Exception;
7
8
class StatisticsController extends AbstractActionController {
9
10
    public function statisticsAction() {
11
        $statistics = array(
12
            'express_release_date' => '',
13
            'hdd_drive_usage' => 0,
14
            'band_width_usage' => 0,
15
            'panel_state' => '',
16
            'mails_over_quota' => array(),
17
            'mails_count' => 0,
18
            'mails_disk_usge' => 0
19
        );
20
        $this->setReleaseDate($statistics);
21
        $this->setHostingData($statistics);
22
        $this->setPanelData($statistics);
23
        return $statistics;
24
    }
25
26
    private function setReleaseDate(Array &$data) {
27
        try {
28
            $version = basename(realpath(dirname(__FILE__).'/../../../../../../../'));
29
            if($version) {
30
                $year = substr($version, 0, 4);
31
                $month = substr($version, 4, 2);
32
                $day = substr($version, 6, 2);
33
                $hours = substr($version, 8, 2);
34
                $minutes = substr($version, 10, 2);
35
                $seconds = substr($version, 12, 2);
36
                $data['express_release_date'] = $day.'/'.$month.'/'.$year.' '.$hours.':'.$minutes.':'.$seconds;
37
            }
38
        } catch(Exception $exc) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
39
            
40
        }
41
    }
42
43
    private function setHostingData(Array &$data) {
44
        try {
45
            $config = $this->loadConfiguration();
46
            $statistics = new Statistics(array(
47
                'ip' => $config['ip'],
48
                'user' => $config['user'],
49
                'pass' => $config['pass'],
50
                'output' => 'json',
51
                'port' => 2083,
52
                'debug' => 0
53
            ));
54
            $data['hdd_drive_usage'] = $statistics->getHddDiskUsage();
55
            $data['band_width_usage'] = $statistics->getBandwidthUsage();
56
            $data['mails_over_quota'] = $statistics->getEmailsAccountsOverQuota();
57
            $data['mails_count'] = $statistics->getEmailsAccountsCount();
58
            $data['mails_disk_usge'] = $statistics->getEmailsAccountsDiskUsage();
59
        } catch(Exception $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
60
            
61
        }
62
    }
63
64
    private function loadConfiguration() {
65
        $config = $this->getServiceLocator()->get('Config');
66
        if(is_array($config) &&
67
                isset($config['columnis']) &&
68
                isset($config['columnis']['api_settings'])) {
69
            return $config['columnis']['api_settings'];
70
        }
71
        return array();
72
    }
73
74
    private function setPanelData(Array &$data) {
75
        try {
76
            $htaccess = $this->getPublicPath().'.htaccess';
77
            $panelState = array(
78
                'right_env' => SystemStatus::right_env($htaccess),
0 ignored issues
show
Documentation introduced by
$htaccess is of type string, but the function expects a object<ExpressApi\V1\Rpc\Statistics\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
                'right_upload_size' => SystemStatus::right_upload_size(),
80
                'ffmpeg_loaded' => SystemStatus::ffmeg_loaded(),
81
                'magic_quotes_active' => SystemStatus::magic_quotes_active(),
82
                'max_upload_size_format' => SystemStatus::max_upload_size_format()
83
            );
84
            $data['panel_state'] = $panelState;
85
        } catch(Exception $exc) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
86
            
87
        }
88
    }
89
90
    private function getPublicPath() {
91
        $config = $this->getServiceLocator()->get('Config');
92
        if(is_array($config) &&
93
                isset($config['template_assets_resolver']) &&
94
                isset($config['template_assets_resolver']['public_path'])) {
95
            return $config['template_assets_resolver']['public_path'];
96
        }
97
        return '';
98
    }
99
}
100