Completed
Push — master ( e21467...fee253 )
by Agel_Nash
02:28
created
assets/lib/APIHelpers.class.php 3 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,7 +62,6 @@  discard block
 block discarded – undo
62 62
      * @param mixed $data массив
63 63
      * @param string $key ключ массива
64 64
      * @param mixed $default null значение по умолчанию
65
-     * @param Closure $validate null функция дополнительной валидации значения (должна возвращать true или false)
66 65
      * @return mixed
67 66
      */
68 67
     public static function getkey($data, $key, $default = null)
@@ -85,7 +84,7 @@  discard block
 block discarded – undo
85 84
      * @license    GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
86 85
      * @param string $email проверяемый email
87 86
      * @param boolean $dns проверять ли DNS записи
88
-     * @return boolean Результат проверки почтового ящика
87
+     * @return false|string Результат проверки почтового ящика
89 88
      * @author Anton Shevchuk
90 89
      */
91 90
     public static function emailValidate($email, $dns = true)
@@ -160,7 +159,7 @@  discard block
 block discarded – undo
160 159
     }
161 160
 
162 161
     /**
163
-     * @param $data
162
+     * @param string $data
164 163
      * @return bool|false|string
165 164
      */
166 165
     public static function getEnv($data)
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
72 72
             $out = $data[$key];
73 73
         }
74
-        if (!empty($validate) && is_callable($validate)) {
74
+        if ( ! empty($validate) && is_callable($validate)) {
75 75
             $out = (($validate($out) === true) ? $out : $default);
76 76
         }
77 77
         return $out;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     {
93 93
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
94 94
             list(, $domain) = explode("@", $email, 2);
95
-            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
95
+            if ( ! $dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
96 96
                 $error = false;
97 97
             } else {
98 98
                 $error = 'dns';
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             case ($tmp = self::getEnv('HTTP_X_FORWARDED_FOR')):
224 224
                 $out = $tmp;
225 225
                 break;
226
-            case (!empty($_SERVER['REMOTE_ADDR'])):
226
+            case ( ! empty($_SERVER['REMOTE_ADDR'])):
227 227
                 $out = $_SERVER['REMOTE_ADDR'];
228 228
                 break;
229 229
             default:
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             }
360 360
             for ($i = 0; $i < $len; $i++) {
361 361
                 $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8');
362
-                if (!in_array($chr, $data, true)) {
362
+                if ( ! in_array($chr, $data, true)) {
363 363
                     $flag = false;
364 364
                     break;
365 365
                 }
Please login to merge, or discard this patch.
Braces   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@  discard block
 block discarded – undo
3 3
 /**
4 4
  * Class APIhelpers
5 5
  */
6
-class APIhelpers
7
-{
6
+class APIhelpers
7
+{
8 8
     /**
9 9
      * Преобразует первый символ в нижний регистр
10 10
      * @param $str
11 11
      * @param string $encoding - кодировка, по-умолчанию UTF-8
12 12
      * @return string
13 13
      */
14
-    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
-    {
14
+    public static function mb_lcfirst($str, $encoding = 'UTF-8')
15
+    {
16 16
         return mb_strtolower(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
17 17
             $encoding);
18 18
     }
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
      * @param string $encoding - кодировка, по-умолчанию UTF-8
24 24
      * @return string
25 25
      */
26
-    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
-    {
26
+    public static function mb_ucfirst($str, $encoding = 'UTF-8')
27
+    {
28 28
         $str = mb_ereg_replace('^[\ ]+', '', $str);
29 29
         $str = mb_strtoupper(mb_substr($str, 0, 1, $encoding), $encoding) . mb_substr($str, 1, mb_strlen($str),
30 30
                 $encoding);
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
      * @param string $encoding кодировка
44 44
      * @return string
45 45
      */
46
-    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
-    {
46
+    public static function mb_trim_word($html, $len, $encoding = 'UTF-8')
47
+    {
48 48
         $text = trim(preg_replace('|\s+|', ' ', strip_tags($html)));
49 49
         $text = mb_substr($text, 0, $len + 1, $encoding);
50
-        if (mb_substr($text, -1, null, $encoding) == ' ') {
50
+        if (mb_substr($text, -1, null, $encoding) == ' ') {
51 51
             $out = trim($text);
52
-        } else {
52
+        } else {
53 53
             $out = mb_substr($text, 0, mb_strripos($text, ' ', null, $encoding), $encoding);
54 54
         }
55 55
 
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
      * @param Closure $validate null функция дополнительной валидации значения (должна возвращать true или false)
66 66
      * @return mixed
67 67
      */
68
-    public static function getkey($data, $key, $default = null)
69
-    {
68
+    public static function getkey($data, $key, $default = null)
69
+    {
70 70
         $out = $default;
71
-        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
71
+        if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
72 72
             $out = $data[$key];
73 73
         }
74
-        if (!empty($validate) && is_callable($validate)) {
74
+        if (!empty($validate) && is_callable($validate)) {
75 75
             $out = (($validate($out) === true) ? $out : $default);
76 76
         }
77 77
         return $out;
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
      * @return boolean Результат проверки почтового ящика
89 89
      * @author Anton Shevchuk
90 90
      */
91
-    public static function emailValidate($email, $dns = true)
92
-    {
93
-        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
91
+    public static function emailValidate($email, $dns = true)
92
+    {
93
+        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
94 94
             list(, $domain) = explode("@", $email, 2);
95
-            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
95
+            if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
96 96
                 $error = false;
97
-            } else {
97
+            } else {
98 98
                 $error = 'dns';
99 99
             }
100
-        } else {
100
+        } else {
101 101
             $error = 'format';
102 102
         }
103 103
 
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
      * $this->genPass(20,"."); //AMV,>&?J)v55,(^g}Z06
131 131
      * $this->genPass(20,"aaa0aaa.A"); //rtvKja5xb0\KpdiRR1if
132 132
      */
133
-    public static function genPass($len, $data = '')
134
-    {
135
-        if ($data == '') {
133
+    public static function genPass($len, $data = '')
134
+    {
135
+        if ($data == '') {
136 136
             $data = 'Aa0.';
137 137
         }
138 138
         $opt = strlen($data);
139 139
         $pass = array();
140 140
 
141
-        for ($i = $len; $i > 0; $i--) {
142
-            switch ($data[rand(0, ($opt - 1))]) {
141
+        for ($i = $len; $i > 0; $i--) {
142
+            switch ($data[rand(0, ($opt - 1))]) {
143 143
                 case 'A':
144 144
                     $tmp = rand(65, 90);
145 145
                     break;
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      * @param $data
164 164
      * @return bool|false|string
165 165
      */
166
-    public static function getEnv($data)
167
-    {
168
-        switch (true) {
166
+    public static function getEnv($data)
167
+    {
168
+        switch (true) {
169 169
             case (isset($_SERVER[$data])):
170 170
                 $out = $_SERVER[$data];
171 171
                 break;
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
      *
199 199
      * @see http://stackoverflow.com/questions/5036443/php-how-to-block-proxies-from-my-site
200 200
      */
201
-    public static function getUserIP($default = '127.0.0.1')
202
-    {
201
+    public static function getUserIP($default = '127.0.0.1')
202
+    {
203 203
         //Порядок условий зависит от приоритетов
204
-        switch (true) {
204
+        switch (true) {
205 205
             case ($tmp = self::getEnv('HTTP_COMING_FROM')):
206 206
                 $out = $tmp;
207 207
                 break;
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
             '`'   => '&#96;',
256 256
             '%60' => '&#96;'
257 257
         )
258
-    ) {
259
-        switch (true) {
258
+    ) {
259
+        switch (true) {
260 260
             case is_scalar($data):
261 261
                 $out = str_replace(
262 262
                     array_keys($chars),
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                 break;
267 267
             case is_array($data):
268 268
                 $out = $data;
269
-                foreach ($out as $key => &$val) {
269
+                foreach ($out as $key => &$val) {
270 270
                     $val = self::sanitarTag($val, $charset, $chars);
271 271
                 }
272 272
                 break;
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
      * @param string $charset
283 283
      * @return string
284 284
      */
285
-    public static function e($text, $charset = 'UTF-8')
286
-    {
285
+    public static function e($text, $charset = 'UTF-8')
286
+    {
287 287
         return is_scalar($text) ? htmlspecialchars($text, ENT_QUOTES, $charset, false) : '';
288 288
     }
289 289
 
@@ -298,17 +298,17 @@  discard block
 block discarded – undo
298 298
      * @param array $mixArray Примесь символов, которые так же могут использоваться в строке
299 299
      * @return bool
300 300
      */
301
-    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
302
-    {
301
+    public static function checkString($value, $minLen = 1, $alph = array(), $mixArray = array())
302
+    {
303 303
         $flag = true;
304 304
         $len = mb_strlen($value, 'UTF-8');
305 305
         $value = trim($value);
306
-        if (mb_strlen($value, 'UTF-8') == $len) {
306
+        if (mb_strlen($value, 'UTF-8') == $len) {
307 307
             $data = is_array($mixArray) ? $mixArray : array();
308 308
             $alph = is_array($alph) ? array_unique($alph) : array();
309
-            foreach ($alph as $item) {
309
+            foreach ($alph as $item) {
310 310
                 $item = strtolower($item);
311
-                switch ($item) {
311
+                switch ($item) {
312 312
                     case 'rus':
313 313
                         $data = array_merge($data, array(
314 314
                             'А',
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                         break;
349 349
                     case 'num':
350 350
                         $tmp = range('0', '9');
351
-                        foreach ($tmp as $t) {
351
+                        foreach ($tmp as $t) {
352 352
                             $data[] = (string)$t;
353 353
                         }
354 354
                         break;
@@ -357,15 +357,15 @@  discard block
 block discarded – undo
357 357
                         break;
358 358
                 }
359 359
             }
360
-            for ($i = 0; $i < $len; $i++) {
360
+            for ($i = 0; $i < $len; $i++) {
361 361
                 $chr = mb_strtoupper(mb_substr($value, $i, 1, 'UTF-8'), 'UTF-8');
362
-                if (!in_array($chr, $data, true)) {
362
+                if (!in_array($chr, $data, true)) {
363 363
                     $flag = false;
364 364
                     break;
365 365
                 }
366 366
             }
367 367
             $flag = ($flag && $len >= $minLen);
368
-        } else {
368
+        } else {
369 369
             $flag = false;
370 370
         }
371 371
 
@@ -382,18 +382,18 @@  discard block
 block discarded – undo
382 382
      * @param string $sep разделитель ключей при склейке многомерных массивов
383 383
      * @return array массив с переименованными ключами
384 384
      */
385
-    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
386
-    {
385
+    public static function renameKeyArr($data, $prefix = '', $suffix = '', $addPS = '.', $sep = '.')
386
+    {
387 387
         $out = array();
388
-        if ($prefix == '' && $suffix == '') {
388
+        if ($prefix == '' && $suffix == '') {
389 389
             $out = $data;
390
-        } else {
390
+        } else {
391 391
             $InsertPrefix = ($prefix != '') ? ($prefix . $addPS) : '';
392 392
             $InsertSuffix = ($suffix != '') ? ($addPS . $suffix) : '';
393
-            foreach ($data as $key => $item) {
393
+            foreach ($data as $key => $item) {
394 394
                 $key = $InsertPrefix . $key;
395 395
                 $val = null;
396
-                switch (true) {
396
+                switch (true) {
397 397
                     case is_scalar($item):
398 398
                         $val = $item;
399 399
                         break;
Please login to merge, or discard this patch.
assets/lib/Helpers/FS.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
      */
66 66
     private function _pathinfo($file, $mode)
67 67
     {
68
-        if (!is_scalar($file) && !is_scalar($mode)) {
68
+        if ( ! is_scalar($file) && ! is_scalar($mode)) {
69 69
             $file = $mode = '';
70 70
         }
71
-        $flag = !(empty($file) || empty($mode));
71
+        $flag = ! (empty($file) || empty($mode));
72 72
         $f = MODX_BASE_PATH . $this->relativePath($file);
73
-        if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
73
+        if ($flag && ! isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
74 74
             $this->_fileInfo[$f] = pathinfo($f);
75 75
         }
76 76
         $out = $flag && isset($this->_fileInfo[$f][$mode]) ? $this->_fileInfo[$f][$mode] : '';
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function takeFileExt($file, $lower = true)
114 114
     {
115 115
         $str = $this->_pathinfo($file, 'extension');
116
-        if($lower){
116
+        if ($lower) {
117 117
             $str = strtolower($str);
118 118
         }
119 119
         return $str;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     {
128 128
         $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : '';
129 129
 
130
-        return (!empty($f) && is_file($f) && is_readable($f));
130
+        return ( ! empty($f) && is_file($f) && is_readable($f));
131 131
     }
132 132
 
133 133
     /**
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
     {
139 139
         $f = is_scalar($path) ? $this->relativePath($path) : '';
140 140
 
141
-        return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f));
141
+        return ( ! empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f));
142 142
     }
143 143
 
144 144
     /**
@@ -153,10 +153,10 @@  discard block
 block discarded – undo
153 153
             $out = filesize(MODX_BASE_PATH . $this->relativePath($file));
154 154
         }
155 155
         
156
-        if($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
156
+        if ($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
157 157
         if (is_array($format)) {
158 158
             $size = $out > 0 ? floor(log($out, 1024)) : 0;
159
-            $type = isset($format[$size]) ? ' '.$format[$size] : '';
159
+            $type = isset($format[$size]) ? ' ' . $format[$size] : '';
160 160
             $out = number_format($out / pow(1024, $size), 2, '.', ',') . $type;
161 161
         }
162 162
         
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function makeDir($path, $perm = 0755)
230 230
     {
231
-        if (!$this->checkDir($path)) {
231
+        if ( ! $this->checkDir($path)) {
232 232
             $path = MODX_BASE_PATH . $this->relativePath($path);
233 233
             $flag = mkdir($path, $this->toOct($perm), true);
234 234
         } else {
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
             $owner = MODX_BASE_PATH;
294 294
         }
295 295
         $path = str_replace('\\', '/', $path);
296
-        if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
296
+        if ( ! (empty($path) || ! is_scalar($path)) && ! preg_match("/^http(s)?:\/\/\w+/", $path)) {
297 297
             $path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), DIRECTORY_SEPARATOR);
298 298
         } else {
299 299
             $path = '';
Please login to merge, or discard this patch.
Braces   +73 added lines, -70 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
  * Class FS
5 5
  * @package Helpers
6 6
  */
7
-class FS
8
-{
7
+class FS
8
+{
9 9
     /**
10 10
      * @var FS cached reference to singleton instance
11 11
      */
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @return self
23 23
      */
24
-    public static function getInstance()
25
-    {
26
-        if (null === self::$instance) {
24
+    public static function getInstance()
25
+    {
26
+        if (null === self::$instance) {
27 27
             self::$instance = new self();
28 28
         }
29 29
 
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
      * is not allowed to call from outside: private!
35 35
      *
36 36
      */
37
-    private function __construct()
38
-    {
37
+    private function __construct()
38
+    {
39 39
     }
40 40
 
41 41
     /**
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @return void
45 45
      */
46
-    private function __clone()
47
-    {
46
+    private function __clone()
47
+    {
48 48
     }
49 49
 
50 50
     /**
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    private function __wakeup()
56
-    {
55
+    private function __wakeup()
56
+    {
57 57
     }
58 58
 
59 59
     /**
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
      * @param string $file ключ
64 64
      * @return string информация из pathinfo о обрабатываемом файле input
65 65
      */
66
-    private function _pathinfo($file, $mode)
67
-    {
68
-        if (!is_scalar($file) && !is_scalar($mode)) {
66
+    private function _pathinfo($file, $mode)
67
+    {
68
+        if (!is_scalar($file) && !is_scalar($mode)) {
69 69
             $file = $mode = '';
70 70
         }
71 71
         $flag = !(empty($file) || empty($mode));
72 72
         $f = MODX_BASE_PATH . $this->relativePath($file);
73
-        if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
73
+        if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
74 74
             $this->_fileInfo[$f] = pathinfo($f);
75 75
         }
76 76
         $out = $flag && isset($this->_fileInfo[$f][$mode]) ? $this->_fileInfo[$f][$mode] : '';
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
      * @param $file
83 83
      * @return string
84 84
      */
85
-    public function takeFileDir($file)
86
-    {
85
+    public function takeFileDir($file)
86
+    {
87 87
         return $this->_pathinfo($file, 'dirname');
88 88
     }
89 89
 
@@ -91,8 +91,9 @@  discard block
 block discarded – undo
91 91
      * @param $file
92 92
      * @return string
93 93
      */
94
-    public function takeFileBasename($file)
95
-    { //file name with extension
94
+    public function takeFileBasename($file)
95
+    {
96
+//file name with extension
96 97
         return $this->_pathinfo($file, 'basename');
97 98
     }
98 99
 
@@ -100,8 +101,8 @@  discard block
 block discarded – undo
100 101
      * @param $file
101 102
      * @return string
102 103
      */
103
-    public function takeFileName($file)
104
-    {
104
+    public function takeFileName($file)
105
+    {
105 106
         return $this->_pathinfo($file, 'filename');
106 107
     }
107 108
 
@@ -110,10 +111,10 @@  discard block
 block discarded – undo
110 111
      * @param bool $lower 
111 112
      * @return string
112 113
      */
113
-    public function takeFileExt($file, $lower = true)
114
-    {
114
+    public function takeFileExt($file, $lower = true)
115
+    {
115 116
         $str = $this->_pathinfo($file, 'extension');
116
-        if($lower){
117
+        if($lower) {
117 118
             $str = strtolower($str);
118 119
         }
119 120
         return $str;
@@ -123,8 +124,8 @@  discard block
 block discarded – undo
123 124
      * @param $file
124 125
      * @return bool
125 126
      */
126
-    public function checkFile($file)
127
-    {
127
+    public function checkFile($file)
128
+    {
128 129
         $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : '';
129 130
 
130 131
         return (!empty($f) && is_file($f) && is_readable($f));
@@ -134,8 +135,8 @@  discard block
 block discarded – undo
134 135
      * @param $path
135 136
      * @return bool
136 137
      */
137
-    public function checkDir($path)
138
-    {
138
+    public function checkDir($path)
139
+    {
139 140
         $f = is_scalar($path) ? $this->relativePath($path) : '';
140 141
 
141 142
         return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f));
@@ -146,15 +147,17 @@  discard block
 block discarded – undo
146 147
      * @param bool|array $format
147 148
      * @return int|string
148 149
      */
149
-    public function fileSize($file, $format = false)
150
-    {
150
+    public function fileSize($file, $format = false)
151
+    {
151 152
         $out = 0;
152
-        if ($this->checkFile($file)) {
153
+        if ($this->checkFile($file)) {
153 154
             $out = filesize(MODX_BASE_PATH . $this->relativePath($file));
154 155
         }
155 156
         
156
-        if($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
157
-        if (is_array($format)) {
157
+        if($format === true) {
158
+            $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
159
+        }
160
+        if (is_array($format)) {
158 161
             $size = $out > 0 ? floor(log($out, 1024)) : 0;
159 162
             $type = isset($format[$size]) ? ' '.$format[$size] : '';
160 163
             $out = number_format($out / pow(1024, $size), 2, '.', ',') . $type;
@@ -173,17 +176,17 @@  discard block
 block discarded – undo
173 176
      * @param string $file Имя файла
174 177
      * @return null|string MIME тип файла
175 178
      */
176
-    public function takeFileMIME($file)
177
-    {
179
+    public function takeFileMIME($file)
180
+    {
178 181
         $out = null;
179 182
         $path = $this->relativePath($file);
180
-        if ($this->checkFile($path)) {
183
+        if ($this->checkFile($path)) {
181 184
             $fname = MODX_BASE_PATH . $path;
182
-            switch (true) {
185
+            switch (true) {
183 186
                 /** need fileinfo extension */
184 187
                 case (extension_loaded('fileinfo') && class_exists('\finfo')):
185 188
                     $fi = new \finfo(FILEINFO_MIME_TYPE);
186
-                    if ($fi) {
189
+                    if ($fi) {
187 190
                         $out = $fi->file($fname);
188 191
                     }
189 192
                     break;
@@ -195,10 +198,10 @@  discard block
 block discarded – undo
195 198
                      * @see: http://www.php.net/manual/ru/function.finfo-open.php#112617
196 199
                      */
197 200
                     $fh = fopen($fname, 'rb');
198
-                    if ($fh) {
201
+                    if ($fh) {
199 202
                         $bytes6 = fread($fh, 6);
200 203
                         fclose($fh);
201
-                        switch (true) {
204
+                        switch (true) {
202 205
                             case ($bytes6 === false):
203 206
                                 break;
204 207
                             case (substr($bytes6, 0, 3) == "\xff\xd8\xff"):
@@ -226,12 +229,12 @@  discard block
 block discarded – undo
226 229
      * @param int $perm
227 230
      * @return bool
228 231
      */
229
-    public function makeDir($path, $perm = 0755)
230
-    {
231
-        if (!$this->checkDir($path)) {
232
+    public function makeDir($path, $perm = 0755)
233
+    {
234
+        if (!$this->checkDir($path)) {
232 235
             $path = MODX_BASE_PATH . $this->relativePath($path);
233 236
             $flag = mkdir($path, $this->toOct($perm), true);
234
-        } else {
237
+        } else {
235 238
             $flag = true;
236 239
         }
237 240
 
@@ -245,13 +248,13 @@  discard block
 block discarded – undo
245 248
      * @param string $to получатель
246 249
      * @return bool статус копирования
247 250
      */
248
-    public function copyFile($from, $to, $chmod = 0644)
249
-    {
251
+    public function copyFile($from, $to, $chmod = 0644)
252
+    {
250 253
         $flag = false;
251 254
         $from = MODX_BASE_PATH . $this->relativePath($from);
252 255
         $to = MODX_BASE_PATH . $this->relativePath($to);
253 256
         $dir = $this->takeFileDir($to);
254
-        if ($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)) {
257
+        if ($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)) {
255 258
             chmod($to, $this->toOct($chmod));
256 259
             $flag = true;
257 260
         }
@@ -266,13 +269,13 @@  discard block
 block discarded – undo
266 269
      * @param string $to получатель
267 270
      * @return bool статус перемещения
268 271
      */
269
-    public function moveFile($from, $to, $chmod = 0644)
270
-    {
272
+    public function moveFile($from, $to, $chmod = 0644)
273
+    {
271 274
         $flag = false;
272 275
         $from = MODX_BASE_PATH . $this->relativePath($from);
273 276
         $to = MODX_BASE_PATH . $this->relativePath($to);
274 277
         $dir = $this->takeFileDir($to);
275
-        if ($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)) {
278
+        if ($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)) {
276 279
             chmod($to, $this->toOct($chmod));
277 280
             $flag = true;
278 281
         }
@@ -287,15 +290,15 @@  discard block
 block discarded – undo
287 290
      * @param string $owner начальный путь который стоит вырезать
288 291
      * @return string относительный путь
289 292
      */
290
-    public function relativePath($path, $owner = null)
291
-    {
292
-        if (is_null($owner)) {
293
+    public function relativePath($path, $owner = null)
294
+    {
295
+        if (is_null($owner)) {
293 296
             $owner = MODX_BASE_PATH;
294 297
         }
295 298
         $path = str_replace('\\', '/', $path);
296
-        if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
299
+        if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
297 300
             $path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), DIRECTORY_SEPARATOR);
298
-        } else {
301
+        } else {
299 302
             $path = '';
300 303
         }
301 304
 
@@ -314,8 +317,8 @@  discard block
 block discarded – undo
314 317
      * @param  mixed $chmod строка или число в восьмеричной/десятичной системе счисления
315 318
      * @return int        число в восьмеричной системе счисления
316 319
      */
317
-    public function toOct($chmod)
318
-    {
320
+    public function toOct($chmod)
321
+    {
319 322
         return is_string($chmod) ? octdec($chmod) : $chmod;
320 323
     }
321 324
 
@@ -323,15 +326,15 @@  discard block
 block discarded – undo
323 326
      * @param $dirPath
324 327
      * @return bool
325 328
      */
326
-    public function rmDir($dirPath)
327
-    {
329
+    public function rmDir($dirPath)
330
+    {
328 331
         $flag = false;
329 332
         $path = $_path = MODX_BASE_PATH . $this->relativePath($dirPath);
330
-        if ($this->checkDir($path)) {
333
+        if ($this->checkDir($path)) {
331 334
             $dirIterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS);
332 335
             $dirRecursiveIterator = new \RecursiveIteratorIterator($dirIterator,
333 336
                 \RecursiveIteratorIterator::CHILD_FIRST);
334
-            foreach ($dirRecursiveIterator as $path) {
337
+            foreach ($dirRecursiveIterator as $path) {
335 338
                 $path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
336 339
             }
337 340
             $flag = rmdir($_path);
@@ -344,10 +347,10 @@  discard block
 block discarded – undo
344 347
      * @param $file
345 348
      * @return bool
346 349
      */
347
-    public function unlink($file)
348
-    {
350
+    public function unlink($file)
351
+    {
349 352
         $flag = false;
350
-        if ($this->checkFile($file)) {
353
+        if ($this->checkFile($file)) {
351 354
             $flag = unlink(MODX_BASE_PATH . $this->relativePath($file));
352 355
         }
353 356
 
@@ -358,10 +361,10 @@  discard block
 block discarded – undo
358 361
      * @param $path
359 362
      * @return bool
360 363
      */
361
-    public function delete($path)
362
-    {
364
+    public function delete($path)
365
+    {
363 366
         $path = MODX_BASE_PATH . $this->relativePath($path);
364
-        switch (true) {
367
+        switch (true) {
365 368
             case $this->checkDir($path):
366 369
                 $flag = $this->rmDir($path);
367 370
                 break;
@@ -380,11 +383,11 @@  discard block
 block discarded – undo
380 383
      * @param bool $full
381 384
      * @return string
382 385
      */
383
-    public function getInexistantFilename($file, $full = false)
384
-    {
386
+    public function getInexistantFilename($file, $full = false)
387
+    {
385 388
         $i = 1;
386 389
         $file = $mainFile = MODX_BASE_PATH . $this->relativePath($file);
387
-        while ($this->checkFile($file)) {
390
+        while ($this->checkFile($file)) {
388 391
             $i++;
389 392
             $out = $this->takeFileDir($file) . '/';
390 393
             $out .= $this->takeFileName($mainFile) . "({$i})." . $this->takeFileExt($file);
Please login to merge, or discard this patch.
assets/lib/Helpers/Config.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public function loadConfig($name)
41 41
     {
42 42
         //$this->debug->debug('Load json config: ' . $this->debug->dumpData($name), 'loadconfig', 2);
43
-        if (!is_scalar($name)) {
43
+        if ( ! is_scalar($name)) {
44 44
             $name = '';
45 45
         }
46 46
         $config = array();
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
      */
118 118
     public function loadArray($arr, $sep = ',')
119 119
     {
120
-        switch(gettype($arr)){
120
+        switch (gettype($arr)) {
121 121
             case 'string':
122 122
                 $out = jsonHelper::jsonDecode($arr, array('assoc' => true));
123
-                if (!is_array($out)) {
123
+                if ( ! is_array($out)) {
124 124
                     $out = $sep ? array_filter(explode($sep, $arr)) : array();
125 125
                 }
126 126
                 break;
Please login to merge, or discard this patch.
Braces   +26 added lines, -25 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
 use jsonHelper;
8 8
 use APIhelpers;
9 9
 
10
-class Config
11
-{
10
+class Config
11
+{
12 12
     private $_cfg = array();
13 13
     protected $fs = null;
14 14
     protected $path = '';
15 15
 
16
-    public function __construct($cfg = array())
17
-    {
18
-        if ($cfg) {
16
+    public function __construct($cfg = array())
17
+    {
18
+        if ($cfg) {
19 19
             $this->setConfig($cfg);
20 20
         }
21 21
         $this->fs = FS::getInstance();
@@ -25,7 +25,8 @@  discard block
 block discarded – undo
25 25
      * @param $path
26 26
      * @return $this
27 27
      */
28
-    public function setPath($path) {
28
+    public function setPath($path)
29
+    {
29 30
         $this->path = $path;
30 31
 
31 32
         return $this;
@@ -37,21 +38,21 @@  discard block
 block discarded – undo
37 38
      * @param $name string имя конфига
38 39
      * @return array массив с настройками
39 40
      */
40
-    public function loadConfig($name)
41
-    {
41
+    public function loadConfig($name)
42
+    {
42 43
         //$this->debug->debug('Load json config: ' . $this->debug->dumpData($name), 'loadconfig', 2);
43
-        if (!is_scalar($name)) {
44
+        if (!is_scalar($name)) {
44 45
             $name = '';
45 46
         }
46 47
         $config = array();
47 48
         $name = explode(";", $name);
48
-        foreach ($name as $cfgName) {
49
+        foreach ($name as $cfgName) {
49 50
             $cfgName = explode(":", $cfgName, 2);
50
-            if (empty($cfgName[1])) {
51
+            if (empty($cfgName[1])) {
51 52
                 $cfgName[1] = 'custom';
52 53
             }
53 54
             $cfgName[1] = rtrim($cfgName[1], '/');
54
-            switch ($cfgName[1]) {
55
+            switch ($cfgName[1]) {
55 56
                 case 'custom':
56 57
                 case 'core':
57 58
                     $configFile = $this->fs->relativePath($this->path) . "/config/{$cfgName[1]}/{$cfgName[0]}.json";
@@ -61,7 +62,7 @@  discard block
 block discarded – undo
61 62
                     break;
62 63
             }
63 64
 
64
-            if ($this->fs->checkFile($configFile)) {
65
+            if ($this->fs->checkFile($configFile)) {
65 66
                 $json = file_get_contents(MODX_BASE_PATH . $configFile);
66 67
                 $config = array_merge($config, jsonHelper::jsonDecode($json, array('assoc' => true), true));
67 68
             }
@@ -76,8 +77,8 @@  discard block
 block discarded – undo
76 77
      * Получение всего списка настроек
77 78
      * @return array
78 79
      */
79
-    public function getConfig()
80
-    {
80
+    public function getConfig()
81
+    {
81 82
         return $this->_cfg;
82 83
     }
83 84
 
@@ -86,12 +87,12 @@  discard block
 block discarded – undo
86 87
      * @param array $cfg массив настроек
87 88
      * @return int результат сохранения настроек
88 89
      */
89
-    public function setConfig($cfg, $overwrite = false)
90
-    {
91
-        if (is_array($cfg)) {
90
+    public function setConfig($cfg, $overwrite = false)
91
+    {
92
+        if (is_array($cfg)) {
92 93
             $this->_cfg = $overwrite ? $cfg : array_merge($this->_cfg, $cfg);
93 94
             $ret = count($this->_cfg);
94
-        } else {
95
+        } else {
95 96
             $ret = false;
96 97
         }
97 98
 
@@ -103,8 +104,8 @@  discard block
 block discarded – undo
103 104
      * @param null $def
104 105
      * @return mixed
105 106
      */
106
-    public function getCFGDef($name, $def = null)
107
-    {
107
+    public function getCFGDef($name, $def = null)
108
+    {
108 109
         return APIhelpers::getkey($this->_cfg, $name, $def);
109 110
     }
110 111
 
@@ -115,12 +116,12 @@  discard block
 block discarded – undo
115 116
      * @param string $sep
116 117
      * @return array|mixed|\xNop
117 118
      */
118
-    public function loadArray($arr, $sep = ',')
119
-    {
120
-        switch(gettype($arr)){
119
+    public function loadArray($arr, $sep = ',')
120
+    {
121
+        switch(gettype($arr)) {
121 122
             case 'string':
122 123
                 $out = jsonHelper::jsonDecode($arr, array('assoc' => true));
123
-                if (!is_array($out)) {
124
+                if (!is_array($out)) {
124 125
                     $out = $sep ? array_filter(explode($sep, $arr)) : array();
125 126
                 }
126 127
                 break;
Please login to merge, or discard this patch.