SystemStatus::right_env()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
/*
4
 * To change this template, choose Tools | Templates
5
 * and open the template in the editor.
6
 */
7
8
/**
9
 * Description of Imagenes
10
 *
11
 * @author matiasfuster
12
 */
13
14
namespace ExpressApi\V1\Rpc\Statistics;
15
16
class SystemStatus {
17
18
    public static function right_upload_size() {
19
        $maxSize = self::max_upload_size();
20
        return $maxSize >= 15 * 1024 * 1024;
21
    }
22
23
    /**
24
     * Retorna si esta correctamente configurado el htaccess para que levante el php.ini correspondiente.
25
     * @param type $file Ruta hacia el .htaccess
26
     * @return type
27
     */
28
    public static function right_env($file) {
29
        $retorno = true;
30
        if(is_file($file)) {
31
            $env = "suPHP_ConfigPath ".dirname(realpath($file));
32
            $htaccess = file($file);
33
            for($i = 0; $i < count($htaccess); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
34
                $htaccess[$i] = trim($htaccess[$i]);
35
            }
36
            $retorno = array_search($env, $htaccess) !== false;
37
        }
38
        return $retorno;
39
    }
40
41
    public static function ffmeg_loaded() {
42
        return extension_loaded('ffmpeg');
43
    }
44
45
    public static function magic_quotes_active() {
46
        return (boolean) get_magic_quotes_gpc();
47
    }
48
49
    public static function max_upload_size_format() {
50
        return self::format_bytes(self::max_upload_size(), 0);
51
    }
52
53
    public static function max_upload_size() {
54
        return min(self::let_to_num(ini_get('post_max_size')), self::let_to_num(ini_get('upload_max_filesize')));
55
    }
56
57
    public static function let_to_num($v) {
58
        $l = substr($v, -1);
59
        $ret = substr($v, 0, -1);
60
        switch(strtoupper($l)) {
61
            case 'P':
62
                $ret *= 1024;
63
            case 'T':
64
                $ret *= 1024;
65
            case 'G':
66
                $ret *= 1024;
67
            case 'M':
68
                $ret *= 1024;
69
            case 'K':
70
                $ret *= 1024;
71
                break;
72
        }
73
        return $ret;
74
    }
75
76
    public static function format_bytes($bytes, $precision = 2) {
77
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
78
        $bytes = max($bytes, 0);
79
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
80
        $pow = min($pow, count($units) - 1);
81
        $bytes /= pow(1024, $pow);
82
        return round($bytes, $precision).$units[$pow];
83
    }
84
}
85