@@ -9,32 +9,32 @@ |
||
9 | 9 | |
10 | 10 | namespace Exception { |
11 | 11 | |
12 | - class Captcha extends Exception { |
|
12 | + class Captcha extends Exception { |
|
13 | 13 | |
14 | 14 | protected $message = 'Error generating captcha'; |
15 | 15 | } |
16 | 16 | |
17 | - class Sitemap extends Exception { |
|
17 | + class Sitemap extends Exception { |
|
18 | 18 | |
19 | 19 | protected $message = 'Error generating sitemap'; |
20 | 20 | } |
21 | 21 | |
22 | - class Language extends Exception { |
|
22 | + class Language extends Exception { |
|
23 | 23 | |
24 | 24 | protected $message = 'Languages not found'; |
25 | 25 | } |
26 | 26 | |
27 | - class Template extends Exception { |
|
27 | + class Template extends Exception { |
|
28 | 28 | |
29 | 29 | protected $message = 'Templates not found'; |
30 | 30 | } |
31 | 31 | |
32 | - class View extends Exception { |
|
32 | + class View extends Exception { |
|
33 | 33 | |
34 | 34 | protected $message = 'View is not initialized'; |
35 | 35 | } |
36 | 36 | |
37 | - class ViewFile extends Exception { |
|
37 | + class ViewFile extends Exception { |
|
38 | 38 | |
39 | 39 | protected $message = 'View file \'$value$\' not found'; |
40 | 40 | } |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public static function start(string $name, int $lifetime) : bool { |
21 | 21 | |
22 | - if (session_id()) return true; |
|
22 | + if (session_id()) { |
|
23 | + return true; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | ini_set('session.gc_maxlifetime', $lifetime); |
25 | 27 | |
@@ -47,7 +49,9 @@ discard block |
||
47 | 49 | |
48 | 50 | public static function set(string $name, $value) { |
49 | 51 | |
50 | - if (session_id()) $_SESSION[$name] = $value; |
|
52 | + if (session_id()) { |
|
53 | + $_SESSION[$name] = $value; |
|
54 | + } |
|
51 | 55 | } |
52 | 56 | |
53 | 57 | /** |
@@ -76,7 +80,9 @@ discard block |
||
76 | 80 | |
77 | 81 | public static function delete(string $name) { |
78 | 82 | |
79 | - if (isset($_SESSION[$name])) unset($_SESSION[$name]); |
|
83 | + if (isset($_SESSION[$name])) { |
|
84 | + unset($_SESSION[$name]); |
|
85 | + } |
|
80 | 86 | } |
81 | 87 | } |
82 | 88 | } |
@@ -73,25 +73,25 @@ discard block |
||
73 | 73 | |
74 | 74 | $pattern = [ |
75 | 75 | |
76 | - 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', |
|
77 | - 'Д' => 'D', 'Е' => 'E', 'Ж' => 'ZH', 'З' => 'Z', |
|
78 | - 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', |
|
79 | - 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', |
|
80 | - 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', |
|
81 | - 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'CH', |
|
82 | - 'Ш' => 'SH', 'Щ' => 'SCH', 'Ъ' => '', 'Ь' => '', |
|
83 | - 'Ы' => 'Y', 'Э' => 'E', 'Ю' => 'JU', 'Я' => 'JA', |
|
84 | - 'І' => 'I', 'Ї' => 'JI', 'Ё' => 'JO', |
|
85 | - |
|
86 | - 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', |
|
87 | - 'д' => 'd', 'е' => 'e', 'ж' => 'zh', 'з' => 'z', |
|
88 | - 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', |
|
89 | - 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', |
|
90 | - 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', |
|
91 | - 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', |
|
92 | - 'ш' => 'sh', 'щ' => 'sch', 'ъ' => '', 'ь' => '', |
|
93 | - 'ы' => 'y', 'э' => 'e', 'ю' => 'ju', 'я' => 'ja', |
|
94 | - 'і' => 'i', 'ї' => 'ji', 'ё' => 'jo' |
|
76 | + 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', |
|
77 | + 'Д' => 'D', 'Е' => 'E', 'Ж' => 'ZH', 'З' => 'Z', |
|
78 | + 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', |
|
79 | + 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', |
|
80 | + 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', |
|
81 | + 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'CH', |
|
82 | + 'Ш' => 'SH', 'Щ' => 'SCH', 'Ъ' => '', 'Ь' => '', |
|
83 | + 'Ы' => 'Y', 'Э' => 'E', 'Ю' => 'JU', 'Я' => 'JA', |
|
84 | + 'І' => 'I', 'Ї' => 'JI', 'Ё' => 'JO', |
|
85 | + |
|
86 | + 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', |
|
87 | + 'д' => 'd', 'е' => 'e', 'ж' => 'zh', 'з' => 'z', |
|
88 | + 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', |
|
89 | + 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', |
|
90 | + 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', |
|
91 | + 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', |
|
92 | + 'ш' => 'sh', 'щ' => 'sch', 'ъ' => '', 'ь' => '', |
|
93 | + 'ы' => 'y', 'э' => 'e', 'ю' => 'ju', 'я' => 'ja', |
|
94 | + 'і' => 'i', 'ї' => 'ji', 'ё' => 'jo' |
|
95 | 95 | ]; |
96 | 96 | |
97 | 97 | # ------------------------ |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | if (($maxlength < 1) || (self::length($string = trim($string)) <= $maxlength)) return $string; |
178 | 178 | |
179 | - $string = (rtrim(self::substr($string, 0, $maxlength)) . ($ellipsis ? '...' : '')); |
|
179 | + $string = (rtrim(self::substr($string, 0, $maxlength)).($ellipsis ? '...' : '')); |
|
180 | 180 | |
181 | 181 | # ------------------------ |
182 | 182 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | public static function encode(string $salt, string $string) : string { |
206 | 206 | |
207 | - return sha1($salt . substr(sha1($string), 8, 32)); |
|
207 | + return sha1($salt.substr(sha1($string), 8, 32)); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | } |
@@ -22,14 +22,18 @@ discard block |
||
22 | 22 | |
23 | 23 | foreach (($string = explode("\n", $string)) as $key => $line) { |
24 | 24 | |
25 | - if ($multiline && $codestyle) $string[$key] = rtrim(preg_replace('/[\r\0\x0B]+/', '', $line)); |
|
26 | - |
|
27 | - else $string[$key] = trim(preg_replace(['/[ \t]+/', '/[\r\0\x0B]+/'], [' ', ''], $line)); |
|
25 | + if ($multiline && $codestyle) { |
|
26 | + $string[$key] = rtrim(preg_replace('/[\r\0\x0B]+/', '', $line)); |
|
27 | + } else { |
|
28 | + $string[$key] = trim(preg_replace(['/[ \t]+/', '/[\r\0\x0B]+/'], [' ', ''], $line)); |
|
29 | + } |
|
28 | 30 | } |
29 | 31 | |
30 | - if (!$multiline) $string = preg_replace('/ {2,}/', ' ', trim(implode(' ', $string), ' ')); |
|
31 | - |
|
32 | - else $string = preg_replace('/(\r\n){3,}/', "\r\n\r\n", trim(implode("\r\n", $string), "\r\n")); |
|
32 | + if (!$multiline) { |
|
33 | + $string = preg_replace('/ {2,}/', ' ', trim(implode(' ', $string), ' ')); |
|
34 | + } else { |
|
35 | + $string = preg_replace('/(\r\n){3,}/', "\r\n\r\n", trim(implode("\r\n", $string), "\r\n")); |
|
36 | + } |
|
33 | 37 | |
34 | 38 | # ------------------------ |
35 | 39 | |
@@ -174,7 +178,9 @@ discard block |
||
174 | 178 | |
175 | 179 | public static function cut(string $string, int $maxlength, bool $ellipsis = false) : string { |
176 | 180 | |
177 | - if (($maxlength < 1) || (self::length($string = trim($string)) <= $maxlength)) return $string; |
|
181 | + if (($maxlength < 1) || (self::length($string = trim($string)) <= $maxlength)) { |
|
182 | + return $string; |
|
183 | + } |
|
178 | 184 | |
179 | 185 | $string = (rtrim(self::substr($string, 0, $maxlength)) . ($ellipsis ? '...' : '')); |
180 | 186 | |
@@ -189,9 +195,13 @@ discard block |
||
189 | 195 | |
190 | 196 | public static function random(int $length, string $pool = STR_POOL_DEFAULT) : string { |
191 | 197 | |
192 | - if (($length < 1) || (0 === ($pool_length = self::length($pool)))) return ''; |
|
198 | + if (($length < 1) || (0 === ($pool_length = self::length($pool)))) { |
|
199 | + return ''; |
|
200 | + } |
|
193 | 201 | |
194 | - $string = ''; for ($i = 0; $i < $length; $i++) $string .= self::substr($pool, random_int(0, ($pool_length - 1)), 1); |
|
202 | + $string = ''; for ($i = 0; $i < $length; $i++) { |
|
203 | + $string .= self::substr($pool, random_int(0, ($pool_length - 1)), 1); |
|
204 | + } |
|
195 | 205 | |
196 | 206 | # ------------------------ |
197 | 207 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | protected function getValue(string $value) : string { |
32 | 32 | |
33 | - return ('\'' . addslashes($value) . '\''); |
|
33 | + return ('\''.addslashes($value).'\''); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | $parser = function($value) { if (is_scalar($value)) return $this->getValue($value); }; |
43 | 43 | |
44 | - return ('(' . implode(', ', array_filter(array_map($parser, $value))) . ')'); |
|
44 | + return ('('.implode(', ', array_filter(array_map($parser, $value))).')'); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,21 +50,21 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function getOperatable($value) { |
52 | 52 | |
53 | - if (is_scalar($value)) return ('= ' . $this->getValue($value)); |
|
53 | + if (is_scalar($value)) return ('= '.$this->getValue($value)); |
|
54 | 54 | |
55 | - if (is_array($value)) return ('IN ' . $this->getRange($value)); |
|
55 | + if (is_array($value)) return ('IN '.$this->getRange($value)); |
|
56 | 56 | |
57 | - if ($value instanceof Type\Not) return ('NOT ' . $this->getValue($value->get())); |
|
57 | + if ($value instanceof Type\Not) return ('NOT '.$this->getValue($value->get())); |
|
58 | 58 | |
59 | - if ($value instanceof Type\Like) return ('LIKE ' . $this->getValue($value->get())); |
|
59 | + if ($value instanceof Type\Like) return ('LIKE '.$this->getValue($value->get())); |
|
60 | 60 | |
61 | - if ($value instanceof Type\LessThan) return ('< ' . $value->get()); |
|
61 | + if ($value instanceof Type\LessThan) return ('< '.$value->get()); |
|
62 | 62 | |
63 | - if ($value instanceof Type\GreaterThan) return ('> ' . $value->get()); |
|
63 | + if ($value instanceof Type\GreaterThan) return ('> '.$value->get()); |
|
64 | 64 | |
65 | - if ($value instanceof Type\LessThanOrEqual) return ('<= ' . $value->get()); |
|
65 | + if ($value instanceof Type\LessThanOrEqual) return ('<= '.$value->get()); |
|
66 | 66 | |
67 | - if ($value instanceof Type\GreaterThanOrEqual) return ('>= ' . $value->get()); |
|
67 | + if ($value instanceof Type\GreaterThanOrEqual) return ('>= '.$value->get()); |
|
68 | 68 | |
69 | 69 | # ------------------------ |
70 | 70 |
@@ -39,7 +39,10 @@ discard block |
||
39 | 39 | |
40 | 40 | protected function getRange(array $value) : string { |
41 | 41 | |
42 | - $parser = function($value) { if (is_scalar($value)) return $this->getValue($value); }; |
|
42 | + $parser = function($value) { if (is_scalar($value)) { |
|
43 | + return $this->getValue($value); |
|
44 | + } |
|
45 | + }; |
|
43 | 46 | |
44 | 47 | return ('(' . implode(', ', array_filter(array_map($parser, $value))) . ')'); |
45 | 48 | } |
@@ -50,21 +53,37 @@ discard block |
||
50 | 53 | |
51 | 54 | protected function getOperatable($value) { |
52 | 55 | |
53 | - if (is_scalar($value)) return ('= ' . $this->getValue($value)); |
|
56 | + if (is_scalar($value)) { |
|
57 | + return ('= ' . $this->getValue($value)); |
|
58 | + } |
|
54 | 59 | |
55 | - if (is_array($value)) return ('IN ' . $this->getRange($value)); |
|
60 | + if (is_array($value)) { |
|
61 | + return ('IN ' . $this->getRange($value)); |
|
62 | + } |
|
56 | 63 | |
57 | - if ($value instanceof Type\Not) return ('NOT ' . $this->getValue($value->get())); |
|
64 | + if ($value instanceof Type\Not) { |
|
65 | + return ('NOT ' . $this->getValue($value->get())); |
|
66 | + } |
|
58 | 67 | |
59 | - if ($value instanceof Type\Like) return ('LIKE ' . $this->getValue($value->get())); |
|
68 | + if ($value instanceof Type\Like) { |
|
69 | + return ('LIKE ' . $this->getValue($value->get())); |
|
70 | + } |
|
60 | 71 | |
61 | - if ($value instanceof Type\LessThan) return ('< ' . $value->get()); |
|
72 | + if ($value instanceof Type\LessThan) { |
|
73 | + return ('< ' . $value->get()); |
|
74 | + } |
|
62 | 75 | |
63 | - if ($value instanceof Type\GreaterThan) return ('> ' . $value->get()); |
|
76 | + if ($value instanceof Type\GreaterThan) { |
|
77 | + return ('> ' . $value->get()); |
|
78 | + } |
|
64 | 79 | |
65 | - if ($value instanceof Type\LessThanOrEqual) return ('<= ' . $value->get()); |
|
80 | + if ($value instanceof Type\LessThanOrEqual) { |
|
81 | + return ('<= ' . $value->get()); |
|
82 | + } |
|
66 | 83 | |
67 | - if ($value instanceof Type\GreaterThanOrEqual) return ('>= ' . $value->get()); |
|
84 | + if ($value instanceof Type\GreaterThanOrEqual) { |
|
85 | + return ('>= ' . $value->get()); |
|
86 | + } |
|
68 | 87 | |
69 | 88 | # ------------------------ |
70 | 89 | |
@@ -86,7 +105,9 @@ discard block |
||
86 | 105 | |
87 | 106 | protected function getString($source = null, string $pattern = '', string $separator = '') : string { |
88 | 107 | |
89 | - if (!is_array($source)) return (is_scalar($source) ? strval($source) : ''); |
|
108 | + if (!is_array($source)) { |
|
109 | + return (is_scalar($source) ? strval($source) : ''); |
|
110 | + } |
|
90 | 111 | |
91 | 112 | $regexs = ['key' => '/\^([a-z]+)/', 'value' => '/\$([a-z]+)/']; $matches = ['key' => [], 'value' => []]; |
92 | 113 | |
@@ -98,7 +119,9 @@ discard block |
||
98 | 119 | |
99 | 120 | # Parse pattern |
100 | 121 | |
101 | - foreach ($regexs as $name => $regex) preg_match($regex, $pattern, $matches[$name]); |
|
122 | + foreach ($regexs as $name => $regex) { |
|
123 | + preg_match($regex, $pattern, $matches[$name]); |
|
124 | + } |
|
102 | 125 | |
103 | 126 | # Process replacements |
104 | 127 | |
@@ -106,9 +129,12 @@ discard block |
||
106 | 129 | |
107 | 130 | $output[$count] = $pattern; $item = &$output[$count++]; |
108 | 131 | |
109 | - foreach ($matches as $name => $match) if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
132 | + foreach ($matches as $name => $match) { |
|
133 | + if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
110 | 134 | |
111 | - try { $replace = [$this, $parsers[$match[1]]]($$name); } catch (\TypeError $e) { $replace = ''; } |
|
135 | + try { $replace = [$this, $parsers[$match[1]]]($$name); |
|
136 | + } |
|
137 | + } catch (\TypeError $e) { $replace = ''; } |
|
112 | 138 | |
113 | 139 | $item = str_replace($match[0], $replace, $item); |
114 | 140 | } |
@@ -23,15 +23,15 @@ |
||
23 | 23 | |
24 | 24 | $table = $this->getName($table); |
25 | 25 | |
26 | - if ($column !== '*') $column = (($distinct ? 'DISTINCT ' : '') . $this->getName($column)); |
|
26 | + if ($column !== '*') $column = (($distinct ? 'DISTINCT ' : '').$this->getName($column)); |
|
27 | 27 | |
28 | 28 | $condition = $this->getString($condition, '^name $operatable', ' AND '); |
29 | 29 | |
30 | 30 | # Build query |
31 | 31 | |
32 | - $this->query = ('SELECT COUNT(' . $column . ') as count ' . |
|
32 | + $this->query = ('SELECT COUNT('.$column.') as count '. |
|
33 | 33 | |
34 | - 'FROM ' . $table . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
34 | + 'FROM '.$table.($condition ? (' WHERE ('.$condition.')') : '')); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
@@ -23,7 +23,9 @@ |
||
23 | 23 | |
24 | 24 | $table = $this->getName($table); |
25 | 25 | |
26 | - if ($column !== '*') $column = (($distinct ? 'DISTINCT ' : '') . $this->getName($column)); |
|
26 | + if ($column !== '*') { |
|
27 | + $column = (($distinct ? 'DISTINCT ' : '') . $this->getName($column)); |
|
28 | + } |
|
27 | 29 | |
28 | 30 | $condition = $this->getString($condition, '^name $operatable', ' AND '); |
29 | 31 |
@@ -58,7 +58,9 @@ discard block |
||
58 | 58 | |
59 | 59 | public function getRow() { |
60 | 60 | |
61 | - if (!is_object($this->result)) return null; |
|
61 | + if (!is_object($this->result)) { |
|
62 | + return null; |
|
63 | + } |
|
62 | 64 | |
63 | 65 | return mysqli_fetch_assoc($this->result); |
64 | 66 | } |
@@ -69,9 +71,13 @@ discard block |
||
69 | 71 | |
70 | 72 | public function getRows() : array { |
71 | 73 | |
72 | - if (!is_object($this->result)) return []; |
|
74 | + if (!is_object($this->result)) { |
|
75 | + return []; |
|
76 | + } |
|
73 | 77 | |
74 | - $rows = []; while (null !== ($row = $this->getRow())) $rows[] = $row; |
|
78 | + $rows = []; while (null !== ($row = $this->getRow())) { |
|
79 | + $rows[] = $row; |
|
80 | + } |
|
75 | 81 | |
76 | 82 | # ------------------------ |
77 | 83 |
@@ -52,7 +52,9 @@ |
||
52 | 52 | |
53 | 53 | public function addItems(array $items) : Loop { |
54 | 54 | |
55 | - foreach ($items as $item) if (is_array($item)) $this->addItem($item); |
|
55 | + foreach ($items as $item) { |
|
56 | + if (is_array($item)) $this->addItem($item); |
|
57 | + } |
|
56 | 58 | |
57 | 59 | return $this; |
58 | 60 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | if (false === ($mime = self::get($extension))) return false; |
23 | 23 | |
24 | - return (preg_match(('/^' . $type . '\//'), $mime) ? true : false); |
|
24 | + return (preg_match(('/^'.$type.'\//'), $mime) ? true : false); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | public static function __autoload() { |
32 | 32 | |
33 | - self::init(DIR_DATA . 'Mime.php'); |
|
33 | + self::init(DIR_DATA.'Mime.php'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -19,7 +19,9 @@ |
||
19 | 19 | |
20 | 20 | private static function checkType(string $extension, string $type) : bool { |
21 | 21 | |
22 | - if (false === ($mime = self::get($extension))) return false; |
|
22 | + if (false === ($mime = self::get($extension))) { |
|
23 | + return false; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | return (preg_match(('/^' . $type . '\//'), $mime) ? true : false); |
25 | 27 | } |
@@ -19,7 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | private static function addPhrase(string $name, string $value) { |
21 | 21 | |
22 | - if (preg_match(REGEX_LANGUAGE_PHRASE_NAME, $name)) self::$phrases[$name] = $value; |
|
22 | + if (preg_match(REGEX_LANGUAGE_PHRASE_NAME, $name)) { |
|
23 | + self::$phrases[$name] = $value; |
|
24 | + } |
|
23 | 25 | } |
24 | 26 | |
25 | 27 | /** |
@@ -30,9 +32,13 @@ discard block |
||
30 | 32 | |
31 | 33 | public static function load(string $file_name) : bool { |
32 | 34 | |
33 | - if (!is_array($phrases = Explorer::include($file_name))) return false; |
|
35 | + if (!is_array($phrases = Explorer::include($file_name))) { |
|
36 | + return false; |
|
37 | + } |
|
34 | 38 | |
35 | - foreach ($phrases as $name => $value) if (is_scalar($value)) self::addPhrase($name, $value); |
|
39 | + foreach ($phrases as $name => $value) { |
|
40 | + if (is_scalar($value)) self::addPhrase($name, $value); |
|
41 | + } |
|
36 | 42 | |
37 | 43 | # ------------------------ |
38 | 44 |