Skip to content

Commit 6bbaf4b

Browse files
committed
update DocLister
1 parent da2386a commit 6bbaf4b

26 files changed

Lines changed: 274 additions & 199 deletions

assets/lib/APIHelpers.class.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function getkey($data, $key, $default = null, $validate = null)
8080
if (is_array($data) && (is_int($key) || is_string($key)) && $key !== '' && array_key_exists($key, $data)) {
8181
$out = $data[$key];
8282
}
83-
if (!empty($validate) && is_callable($validate)) {
83+
if (! empty($validate) && is_callable($validate)) {
8484
$out = (($validate($out) === true) ? $out : $default);
8585
}
8686
return $out;
@@ -94,14 +94,14 @@ public static function getkey($data, $key, $default = null, $validate = null)
9494
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
9595
* @param string $email проверяемый email
9696
* @param boolean $dns проверять ли DNS записи
97-
* @return boolean Результат проверки почтового ящика
97+
* @return boolean|string Результат проверки почтового ящика
9898
* @author Anton Shevchuk
9999
*/
100100
public static function emailValidate($email, $dns = true)
101101
{
102102
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
103103
list(, $domain) = explode("@", $email, 2);
104-
if (!$dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
104+
if (! $dns || ($dns && checkdnsrr($domain, "MX") && checkdnsrr($domain, "A"))) {
105105
$error = false;
106106
} else {
107107
$error = 'dns';
@@ -232,7 +232,7 @@ public static function getUserIP($default = '127.0.0.1')
232232
case ($tmp = self::getEnv('HTTP_X_FORWARDED_FOR')):
233233
$out = $tmp;
234234
break;
235-
case (!empty($_SERVER['REMOTE_ADDR'])):
235+
case (! empty($_SERVER['REMOTE_ADDR'])):
236236
$out = $_SERVER['REMOTE_ADDR'];
237237
break;
238238
default:
@@ -270,13 +270,14 @@ public static function sanitarTag(
270270
$out = str_replace(
271271
array_keys($chars),
272272
array_values($chars),
273-
is_null($charset) ? $data : self::e($data, $charset)
273+
$charset === null ? $data : self::e($data, $charset)
274274
);
275275
break;
276276
case is_array($data):
277-
$out = $data;
278-
foreach ($out as $key => &$val) {
279-
$val = self::sanitarTag($val, $charset, $chars);
277+
$out = array();
278+
foreach ($data as $key => $val) {
279+
$key = self::sanitarTag($key, $charset, $chars);
280+
$out[$key] = self::sanitarTag($val, $charset, $chars);
280281
}
281282
break;
282283
default:
@@ -402,9 +403,7 @@ public static function cleanIDs($IDs, $sep = ',', $ignore = array())
402403
foreach ($IDs as $item) {
403404
$item = trim($item);
404405
if (is_scalar($item) && (int)$item >= 0) { //Fix 0xfffffffff
405-
if (!empty($ignore) && in_array((int)$item, $ignore, true)) {
406-
$this->log[] = 'Ignore id ' . (int)$item;
407-
} else {
406+
if (empty($ignore) || !\in_array((int)$item, $ignore, true)) {
408407
$out[] = (int)$item;
409408
}
410409
}

assets/lib/Formatter/CSSMinify.php

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class CSSMinify
66

77
public function __construct($cssFilesPath = array())
88
{
9-
if (is_array($cssFilesPath) && !empty($cssFilesPath)) {
9+
if (is_array($cssFilesPath) && ! empty($cssFilesPath)) {
1010
$this->cssPath = $cssFilesPath;
1111
}
1212
}

assets/lib/Formatter/SqlFormatter.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ protected static function getNextToken($string, $previous = null)
834834
} // Non-quoted variable name
835835
else {
836836
preg_match('/^(' . $string[0] . '[a-zA-Z0-9\._\$]+)/', $string, $matches);
837-
if (!empty($matches)) {
837+
if (! empty($matches)) {
838838
$ret[self::TOKEN_VALUE] = $matches[1];
839839
}
840840
}
@@ -863,7 +863,7 @@ protected static function getNextToken($string, $previous = null)
863863

864864
// A reserved word cannot be preceded by a '.'
865865
// this makes it so in "mytable.from", "from" is not considered a reserved word
866-
if (!$previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
866+
if (! $previous || !isset($previous[self::TOKEN_VALUE]) || $previous[self::TOKEN_VALUE] !== '.') {
867867
$upper = strtoupper($string);
868868
// Top Level Reserved Word
869869
if (preg_match('/^(' . self::$regex_reserved_toplevel . ')($|\s|' . self::$regex_boundaries . ')/', $upper,
@@ -1158,7 +1158,7 @@ public static function format($string, $highlight = true)
11581158
$return = rtrim($return, ' ');
11591159
}
11601160

1161-
if (!$inline_parentheses) {
1161+
if (! $inline_parentheses) {
11621162
$increase_block_indent = true;
11631163
// Add a newline after the parentheses
11641164
$newline = true;
@@ -1191,7 +1191,7 @@ public static function format($string, $highlight = true)
11911191
}
11921192

11931193
// Add a newline before the closing parentheses (if not already added)
1194-
if (!$added_newline) {
1194+
if (! $added_newline) {
11951195
$return .= "\n" . str_repeat($tab, $indent_level);
11961196
}
11971197
} // Top level reserved words start a new line and increase the special indent level
@@ -1208,7 +1208,7 @@ public static function format($string, $highlight = true)
12081208
// Add a newline after the top level reserved word
12091209
$newline = true;
12101210
// Add a newline before the top level reserved word (if not already added)
1211-
if (!$added_newline) {
1211+
if (! $added_newline) {
12121212
$return .= "\n" . str_repeat($tab, $indent_level);
12131213
} // If we already added a newline, redo the indentation since it may be different now
12141214
else {
@@ -1222,14 +1222,14 @@ public static function format($string, $highlight = true)
12221222
$highlighted = preg_replace('/\s+/', ' ', $highlighted);
12231223
}
12241224
//if SQL 'LIMIT' clause, start variable to reset newline
1225-
if ($token[self::TOKEN_VALUE] === 'LIMIT' && !$inline_parentheses) {
1225+
if ($token[self::TOKEN_VALUE] === 'LIMIT' && ! $inline_parentheses) {
12261226
$clause_limit = true;
12271227
}
12281228
} // Checks if we are out of the limit clause
12291229
elseif ($clause_limit && $token[self::TOKEN_VALUE] !== "," && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_NUMBER && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE) {
12301230
$clause_limit = false;
12311231
} // Commas start a new line (unless within inline parentheses or SQL 'LIMIT' clause)
1232-
elseif ($token[self::TOKEN_VALUE] === ',' && !$inline_parentheses) {
1232+
elseif ($token[self::TOKEN_VALUE] === ',' && ! $inline_parentheses) {
12331233
//If the previous TOKEN_VALUE is 'LIMIT', resets new line
12341234
if ($clause_limit === true) {
12351235
$newline = false;
@@ -1241,7 +1241,7 @@ public static function format($string, $highlight = true)
12411241
} // Newline reserved words start a new line
12421242
elseif ($token[self::TOKEN_TYPE] === self::TOKEN_TYPE_RESERVED_NEWLINE) {
12431243
// Add a newline before the reserved word (if not already added)
1244-
if (!$added_newline) {
1244+
if (! $added_newline) {
12451245
$return .= "\n" . str_repeat($tab, $indent_level);
12461246
}
12471247

@@ -1335,7 +1335,7 @@ public static function splitQuery($string)
13351335
foreach ($tokens as $token) {
13361336
// If this is a query separator
13371337
if ($token[self::TOKEN_VALUE] === ';') {
1338-
if (!$empty) {
1338+
if (! $empty) {
13391339
$queries[] = $current_query . ';';
13401340
}
13411341
$current_query = '';
@@ -1351,7 +1351,7 @@ public static function splitQuery($string)
13511351
$current_query .= $token[self::TOKEN_VALUE];
13521352
}
13531353

1354-
if (!$empty) {
1354+
if (! $empty) {
13551355
$queries[] = trim($current_query);
13561356
}
13571357

assets/lib/Helpers/Assets.php

100755100644
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class AssetsHelper
1212
* @var \DocumentParser
1313
* @access protected
1414
*/
15-
protected $modx = null;
16-
protected $fs = null;
15+
protected $modx;
16+
17+
/** @var \Helpers\FS */
18+
protected $fs;
1719

1820
/**
1921
* @var AssetsHelper cached reference to singleton instance
@@ -52,7 +54,6 @@ private function __construct(DocumentParser $modx)
5254
*/
5355
private function __clone()
5456
{
55-
5657
}
5758

5859
/**
@@ -62,7 +63,6 @@ private function __clone()
6263
*/
6364
private function __wakeup()
6465
{
65-
6666
}
6767

6868
/**
@@ -94,12 +94,12 @@ public function registerJQuery()
9494
public function registerScript($name, $params)
9595
{
9696
$out = '';
97-
if (!isset($this->modx->loadedjscripts[$name])) {
97+
if (! isset($this->modx->loadedjscripts[$name])) {
9898
$src = $params['src'];
9999
$remote = strpos($src, 'http') === 0 || strpos($src, '//') === 0;
100-
if (!$remote) {
100+
if (! $remote) {
101101
$src = $this->modx->config['site_url'] . $src;
102-
if (!$this->fs->checkFile($params['src'])) {
102+
if (! $this->fs->checkFile($params['src'])) {
103103
$this->modx->logEvent(0, 3, 'Cannot load ' . $src, 'Assets helper');
104104

105105
return $out;
@@ -116,7 +116,6 @@ public function registerScript($name, $params)
116116
}
117117

118118
$this->modx->loadedjscripts[$name] = $params;
119-
120119
}
121120

122121
return $out;
@@ -129,7 +128,9 @@ public function registerScript($name, $params)
129128
public function registerScriptsList($list = array())
130129
{
131130
$out = '';
132-
if (!is_array($list)) return $out;
131+
if (! \is_array($list)) {
132+
return $out;
133+
}
133134

134135
foreach ($list as $script => $params) {
135136
$out .= $this->registerScript($script, $params);

assets/lib/Helpers/Collection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function partition(Closure $p)
9393

9494
/**
9595
* @param $offset
96-
* @param null $length
96+
* @param null|int $length
9797
* @return array
9898
*/
9999
public function slice($offset, $length = null)
@@ -132,7 +132,7 @@ public function append($value)
132132

133133
/**
134134
* @param $data
135-
* @param null $id
135+
* @param null|int|string $id
136136
* @return $this
137137
*/
138138
public function add($data, $id = null)
@@ -280,10 +280,13 @@ public function offsetGet($offset)
280280
*/
281281
public function offsetSet($offset, $value)
282282
{
283-
if (! isset($offset)) {
284-
return $this->add($value);
283+
if ($offset !== null) {
284+
$this->set($offset, $value);
285+
} else {
286+
$this->add($value);
285287
}
286-
$this->set($offset, $value);
288+
289+
return $this;
287290
}
288291

289292
/**

assets/lib/Helpers/Config.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
class Config
1111
{
1212
private $_cfg = array();
13-
protected $fs = null;
13+
/** @var FS */
14+
protected $fs;
1415
protected $path = '';
1516

1617
/**
@@ -20,7 +21,7 @@ class Config
2021
*/
2122
public function __construct($cfg = array())
2223
{
23-
if (!empty($cfg)) {
24+
if (! empty($cfg)) {
2425
$this->setConfig($cfg);
2526
}
2627
$this->fs = FS::getInstance();
@@ -69,7 +70,9 @@ public function loadConfig($name)
6970

7071
if ($this->fs->checkFile($configFile)) {
7172
$json = file_get_contents(MODX_BASE_PATH . $configFile);
72-
$config = array_merge($config, jsonHelper::jsonDecode($json, array('assoc' => true), true));
73+
/** @var array $json */
74+
$json = jsonHelper::jsonDecode($json, array('assoc' => true), true);
75+
$config = array_merge($config, $json);
7376
}
7477
}
7578

@@ -90,7 +93,7 @@ public function getConfig()
9093
/**
9194
* Сохранение массива настроек
9295
* @param array $cfg массив настроек
93-
* @return int результат сохранения настроек
96+
* @return int|bool результат сохранения настроек
9497
*/
9598
public function setConfig($cfg, $overwrite = false)
9699
{
@@ -106,7 +109,7 @@ public function setConfig($cfg, $overwrite = false)
106109

107110
/**
108111
* @param $name
109-
* @param null $def
112+
* @param mixed $def
110113
* @return mixed
111114
*/
112115
public function getCFGDef($name, $def = null)

assets/lib/Helpers/FS.php

100755100644
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function takeFileName($file)
107107

108108
/**
109109
* @param $file
110-
* @param bool $lower
110+
* @param bool $lower
111111
* @return string
112112
*/
113113
public function takeFileExt($file, $lower = true)
@@ -127,7 +127,7 @@ public function checkFile($file)
127127
{
128128
$f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : '';
129129

130-
return (!empty($f) && is_file($f) && is_readable($f));
130+
return (! empty($f) && is_file($f) && is_readable($f));
131131
}
132132

133133
/**
@@ -138,7 +138,7 @@ public function checkDir($path)
138138
{
139139
$f = is_scalar($path) ? $this->relativePath($path) : '';
140140

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));
142142
}
143143

144144
/**
@@ -152,14 +152,14 @@ public function fileSize($file, $format = false)
152152
if ($this->checkFile($file)) {
153153
$out = filesize(MODX_BASE_PATH . $this->relativePath($file));
154154
}
155-
155+
156156
if($format === true) $format = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
157157
if (is_array($format)) {
158158
$size = $out > 0 ? floor(log($out, 1024)) : 0;
159159
$type = isset($format[$size]) ? ' '.$format[$size] : '';
160160
$out = number_format($out / pow(1024, $size), 2, '.', ',') . $type;
161161
}
162-
162+
163163
return $out;
164164
}
165165

@@ -228,7 +228,7 @@ public function takeFileMIME($file)
228228
*/
229229
public function makeDir($path, $perm = 0755)
230230
{
231-
if (!$this->checkDir($path)) {
231+
if (! $this->checkDir($path)) {
232232
$path = MODX_BASE_PATH . $this->relativePath($path);
233233
$flag = mkdir($path, $this->toOct($perm), true);
234234
} else {

0 commit comments

Comments
 (0)