1 | <?php |
||||||
2 | |||||||
3 | class Xcloner_Requirements { |
||||||
4 | |||||||
5 | var $min_php_version = "5.6.0"; |
||||||
6 | var $safe_mode = "Off"; |
||||||
7 | |||||||
8 | private $xcloner_settings; |
||||||
9 | private $xcloner_container; |
||||||
10 | |||||||
11 | public function __construct(Xcloner $xcloner_container) { |
||||||
12 | $this->xcloner_container = $xcloner_container; |
||||||
13 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
||||||
14 | } |
||||||
15 | |||||||
16 | private function get_xcloner_container() { |
||||||
0 ignored issues
–
show
|
|||||||
17 | return $this->xcloner_container; |
||||||
18 | } |
||||||
19 | |||||||
20 | public function check_backup_ready_status() { |
||||||
21 | if (!$this->check_min_php_version(1)) { |
||||||
22 | return false; |
||||||
23 | } |
||||||
24 | |||||||
25 | if (!$this->check_safe_mode(1)) { |
||||||
26 | return false; |
||||||
27 | } |
||||||
28 | |||||||
29 | if (!$this->check_xcloner_start_path(1)) { |
||||||
30 | return false; |
||||||
31 | } |
||||||
32 | |||||||
33 | if (!$this->check_xcloner_store_path(1)) { |
||||||
34 | return false; |
||||||
35 | } |
||||||
36 | |||||||
37 | if (!$this->check_xcloner_tmp_path(1)) { |
||||||
38 | return false; |
||||||
39 | } |
||||||
40 | |||||||
41 | return true; |
||||||
42 | } |
||||||
43 | |||||||
44 | public function get_constant($var) { |
||||||
45 | return $this->$var; |
||||||
46 | } |
||||||
47 | |||||||
48 | public function check_min_php_version($return_bool = 0) { |
||||||
49 | |||||||
50 | if ($return_bool == 1) { |
||||||
51 | if (version_compare(phpversion(), $this->min_php_version, '<')) { |
||||||
52 | return false; |
||||||
53 | } else { |
||||||
54 | return true; |
||||||
55 | } |
||||||
56 | } |
||||||
57 | |||||||
58 | return phpversion(); |
||||||
59 | } |
||||||
60 | |||||||
61 | public function check_safe_mode($return_bool = 0) { |
||||||
0 ignored issues
–
show
The parameter
$return_bool is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
62 | /*no longer needed for PHP 7*/ |
||||||
63 | $safe_mode = "Off"; |
||||||
64 | |||||||
65 | /*if($return_bool) |
||||||
66 | { |
||||||
67 | if( ini_get('safe_mode') ) |
||||||
68 | return false; |
||||||
69 | else |
||||||
70 | return true; |
||||||
71 | } |
||||||
72 | |||||||
73 | if( ini_get('safe_mode') ) |
||||||
74 | $safe_mode = "On"; |
||||||
75 | * */ |
||||||
76 | |||||||
77 | return $safe_mode; |
||||||
78 | } |
||||||
79 | |||||||
80 | public function check_xcloner_start_path($return_bool = 0) { |
||||||
81 | $path = $this->xcloner_settings->get_xcloner_start_path(); |
||||||
0 ignored issues
–
show
The method
get_xcloner_start_path() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
82 | |||||||
83 | if ($return_bool) { |
||||||
84 | if (!file_exists($path)) { |
||||||
85 | return false; |
||||||
86 | } |
||||||
87 | |||||||
88 | return is_readable($path); |
||||||
89 | } |
||||||
90 | |||||||
91 | return $path; |
||||||
92 | } |
||||||
93 | |||||||
94 | public function check_xcloner_tmp_path($return_bool = 0) { |
||||||
95 | $path = $this->xcloner_settings->get_xcloner_tmp_path(); |
||||||
96 | |||||||
97 | if ($return_bool) { |
||||||
98 | if (!file_exists($path)) { |
||||||
99 | return false; |
||||||
100 | } |
||||||
101 | |||||||
102 | if (!is_writeable($path)) { |
||||||
103 | @chmod($path, 0777); |
||||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
chmod() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||||
104 | } |
||||||
105 | |||||||
106 | return is_writeable($path); |
||||||
107 | } |
||||||
108 | |||||||
109 | return $path; |
||||||
110 | } |
||||||
111 | |||||||
112 | public function check_xcloner_store_path($return_bool = 0) { |
||||||
113 | $path = $this->xcloner_settings->get_xcloner_store_path(); |
||||||
114 | |||||||
115 | if ($return_bool) { |
||||||
116 | if (!file_exists($path)) { |
||||||
117 | return false; |
||||||
118 | } |
||||||
119 | |||||||
120 | if (!is_writeable($path)) { |
||||||
121 | @chmod($path, 0777); |
||||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
chmod() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||||
122 | } |
||||||
123 | |||||||
124 | return is_writeable($path); |
||||||
125 | } |
||||||
126 | |||||||
127 | return $path; |
||||||
128 | } |
||||||
129 | |||||||
130 | public function get_max_execution_time() { |
||||||
131 | return ini_get('max_execution_time'); |
||||||
132 | } |
||||||
133 | |||||||
134 | public function get_memory_limit() { |
||||||
135 | return ini_get('memory_limit'); |
||||||
136 | } |
||||||
137 | |||||||
138 | public function get_open_basedir() { |
||||||
139 | $open_basedir = ini_get('open_basedir'); |
||||||
140 | |||||||
141 | if (!$open_basedir) { |
||||||
142 | $open_basedir = "none"; |
||||||
143 | } |
||||||
144 | |||||||
145 | return $open_basedir; |
||||||
146 | } |
||||||
147 | |||||||
148 | public function get_free_disk_space() { |
||||||
149 | return $this->file_format_size(disk_free_space($this->xcloner_settings->get_xcloner_store_path())); |
||||||
150 | } |
||||||
151 | |||||||
152 | public function file_format_size($bytes, $decimals = 2) { |
||||||
153 | $unit_list = array('B', 'KB', 'MB', 'GB', 'PB'); |
||||||
154 | |||||||
155 | if ($bytes == 0) { |
||||||
156 | return $bytes.' '.$unit_list[0]; |
||||||
157 | } |
||||||
158 | |||||||
159 | $unit_count = count($unit_list); |
||||||
160 | for ($i = $unit_count - 1; $i >= 0; $i--) { |
||||||
161 | $power = $i * 10; |
||||||
162 | if (($bytes >> $power) >= 1) { |
||||||
163 | return round($bytes / (1 << $power), $decimals).' '.$unit_list[$i]; |
||||||
164 | } |
||||||
165 | } |
||||||
166 | } |
||||||
167 | } |
||||||
168 | |||||||
169 | ?> |
||||||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||||||
170 |
This check looks for private methods that have been defined, but are not used inside the class.