@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public static function stringify(SimpleXMLElement $xml) { |
| 32 | 32 | |
| 33 | - if (false === ($xml = dom_import_simplexml($xml))) return false; |
|
| 33 | + if (false === ($xml = dom_import_simplexml($xml))) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | $dom = $xml->ownerDocument; $dom->formatOutput = true; |
| 36 | 38 | |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | |
| 48 | 50 | public static function load(string $file_name) { |
| 49 | 51 | |
| 50 | - if (false === ($contents = Explorer::getContents($file_name))) return false; |
|
| 52 | + if (false === ($contents = Explorer::getContents($file_name))) { |
|
| 53 | + return false; |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | return self::parse($contents); |
| 53 | 57 | } |
@@ -60,7 +64,9 @@ discard block |
||
| 60 | 64 | |
| 61 | 65 | public static function save(string $file_name, SimpleXMLElement $xml) { |
| 62 | 66 | |
| 63 | - if (false === ($xml = self::stringify($xml))) return false; |
|
| 67 | + if (false === ($xml = self::stringify($xml))) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | return Explorer::putContents($file_name, $xml); |
| 66 | 72 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * Parse a string as XML |
| 16 | 16 | * |
| 17 | - * @return the XML object or false on failure |
|
| 17 | + * @return SimpleXMLElement XML object or false on failure |
|
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | public static function parse(string $string) { |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | /** |
| 26 | 26 | * Convert an XML object to a string |
| 27 | 27 | * |
| 28 | - * @return the string or false on failure |
|
| 28 | + * @return string string or false on failure |
|
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | public static function stringify(SimpleXMLElement $xml) { |
@@ -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) { |
| 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 | |
@@ -19,17 +19,17 @@ |
||
| 19 | 19 | |
| 20 | 20 | # Check basic types |
| 21 | 21 | |
| 22 | - if (is_string ($default)) return function(string $value) { return $value; }; |
|
| 22 | + if (is_string($default)) return function(string $value) { return $value; }; |
|
| 23 | 23 | |
| 24 | - if (is_bool ($default)) return function(bool $value) { return $value; }; |
|
| 24 | + if (is_bool($default)) return function(bool $value) { return $value; }; |
|
| 25 | 25 | |
| 26 | - if (is_int ($default)) return function(int $value) { return $value; }; |
|
| 26 | + if (is_int($default)) return function(int $value) { return $value; }; |
|
| 27 | 27 | |
| 28 | - if (is_float ($default)) return function(float $value) { return $value; }; |
|
| 28 | + if (is_float($default)) return function(float $value) { return $value; }; |
|
| 29 | 29 | |
| 30 | - if (is_array ($default)) return function(array $value) { return $value; }; |
|
| 30 | + if (is_array($default)) return function(array $value) { return $value; }; |
|
| 31 | 31 | |
| 32 | - if (is_callable ($default)) return function(callable $value) { return $value; }; |
|
| 32 | + if (is_callable($default)) return function(callable $value) { return $value; }; |
|
| 33 | 33 | |
| 34 | 34 | # Check object type |
| 35 | 35 | |
@@ -19,28 +19,51 @@ |
||
| 19 | 19 | |
| 20 | 20 | # Check basic types |
| 21 | 21 | |
| 22 | - if (is_string ($default)) return function(string $value) { return $value; }; |
|
| 22 | + if (is_string ($default)) { |
|
| 23 | + return function(string $value) { return $value; |
|
| 24 | + } |
|
| 25 | + }; |
|
| 23 | 26 | |
| 24 | - if (is_bool ($default)) return function(bool $value) { return $value; }; |
|
| 27 | + if (is_bool ($default)) { |
|
| 28 | + return function(bool $value) { return $value; |
|
| 29 | + } |
|
| 30 | + }; |
|
| 25 | 31 | |
| 26 | - if (is_int ($default)) return function(int $value) { return $value; }; |
|
| 32 | + if (is_int ($default)) { |
|
| 33 | + return function(int $value) { return $value; |
|
| 34 | + } |
|
| 35 | + }; |
|
| 27 | 36 | |
| 28 | - if (is_float ($default)) return function(float $value) { return $value; }; |
|
| 37 | + if (is_float ($default)) { |
|
| 38 | + return function(float $value) { return $value; |
|
| 39 | + } |
|
| 40 | + }; |
|
| 29 | 41 | |
| 30 | - if (is_array ($default)) return function(array $value) { return $value; }; |
|
| 42 | + if (is_array ($default)) { |
|
| 43 | + return function(array $value) { return $value; |
|
| 44 | + } |
|
| 45 | + }; |
|
| 31 | 46 | |
| 32 | - if (is_callable ($default)) return function(callable $value) { return $value; }; |
|
| 47 | + if (is_callable ($default)) { |
|
| 48 | + return function(callable $value) { return $value; |
|
| 49 | + } |
|
| 50 | + }; |
|
| 33 | 51 | |
| 34 | 52 | # Check object type |
| 35 | 53 | |
| 36 | - if (is_object($default)) return function($value) use($default) { |
|
| 54 | + if (is_object($default)) { |
|
| 55 | + return function($value) use($default) { |
|
| 37 | 56 | |
| 38 | 57 | return (is_a($value, get_class($default)) ? $value : null); |
| 58 | + } |
|
| 39 | 59 | }; |
| 40 | 60 | |
| 41 | 61 | # Check resource type |
| 42 | 62 | |
| 43 | - if (is_resource($default)) return function($value) { return (is_resource($value) ? $value : null); }; |
|
| 63 | + if (is_resource($default)) { |
|
| 64 | + return function($value) { return (is_resource($value) ? $value : null); |
|
| 65 | + } |
|
| 66 | + }; |
|
| 44 | 67 | |
| 45 | 68 | # ------------------------ |
| 46 | 69 | |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | # Build query |
| 31 | 31 | |
| 32 | - $this->query = ('UPDATE ' . $table . ' SET ' . $set . ($condition ? (' WHERE (' . $condition . ')') : '')); |
|
| 32 | + $this->query = ('UPDATE '.$table.' SET '.$set.($condition ? (' WHERE ('.$condition.')') : '')); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | } |
@@ -21,19 +21,29 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | # Establish connection |
| 23 | 23 | |
| 24 | - if (false === ($link = mysqli_connect($server, $user, $password))) throw new Exception\DBConnect(); |
|
| 24 | + if (false === ($link = mysqli_connect($server, $user, $password))) { |
|
| 25 | + throw new Exception\DBConnect(); |
|
| 26 | + } |
|
| 25 | 27 | |
| 26 | 28 | # Select database |
| 27 | 29 | |
| 28 | - if (!mysqli_select_db($link, $name)) throw new Exception\DBSelect(); |
|
| 30 | + if (!mysqli_select_db($link, $name)) { |
|
| 31 | + throw new Exception\DBSelect(); |
|
| 32 | + } |
|
| 29 | 33 | |
| 30 | 34 | # Set encoding |
| 31 | 35 | |
| 32 | - if (!mysqli_query($link, "SET character_set_client = 'utf8'")) throw new Exception\DBCharset(); |
|
| 36 | + if (!mysqli_query($link, "SET character_set_client = 'utf8'")) { |
|
| 37 | + throw new Exception\DBCharset(); |
|
| 38 | + } |
|
| 33 | 39 | |
| 34 | - if (!mysqli_query($link, "SET character_set_results = 'utf8'")) throw new Exception\DBCharset(); |
|
| 40 | + if (!mysqli_query($link, "SET character_set_results = 'utf8'")) { |
|
| 41 | + throw new Exception\DBCharset(); |
|
| 42 | + } |
|
| 35 | 43 | |
| 36 | - if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) throw new Exception\DBCharset(); |
|
| 44 | + if (!mysqli_query($link, "SET collation_connection = 'utf8_general_ci'")) { |
|
| 45 | + throw new Exception\DBCharset(); |
|
| 46 | + } |
|
| 37 | 47 | |
| 38 | 48 | # ------------------------ |
| 39 | 49 | |
@@ -48,7 +58,9 @@ discard block |
||
| 48 | 58 | |
| 49 | 59 | public static function send(string $query) { |
| 50 | 60 | |
| 51 | - if (null === self::$link) return (self::$last = false); |
|
| 61 | + if (null === self::$link) { |
|
| 62 | + return (self::$last = false); |
|
| 63 | + } |
|
| 52 | 64 | |
| 53 | 65 | $time = microtime(true); $result = mysqli_query(self::$link, $query); $time = (microtime(true) - $time); |
| 54 | 66 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | |
| 18 | 18 | protected function getValue(string $value) { |
| 19 | 19 | |
| 20 | - return ('\'' . addslashes($value) . '\''); |
|
| 20 | + return ('\''.addslashes($value).'\''); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | # Get field sort |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | protected function getString($source = null, string $pattern = '', string $separator = '') { |
| 33 | 33 | |
| 34 | - if (!is_array($source)) return (is_scalar($source) ? strval($source) : ''); |
|
| 34 | + if (!is_array($source)) { |
|
| 35 | + return (is_scalar($source) ? strval($source) : ''); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | $regexs = ['key' => '/\^([a-z]+)/', 'value' => '/\$([a-z]+)/']; $matches = ['key' => [], 'value' => []]; |
| 37 | 39 | |
@@ -39,18 +41,25 @@ discard block |
||
| 39 | 41 | |
| 40 | 42 | # Parse pattern |
| 41 | 43 | |
| 42 | - foreach ($regexs as $name => $regex) preg_match($regex, $pattern, $matches[$name]); |
|
| 44 | + foreach ($regexs as $name => $regex) { |
|
| 45 | + preg_match($regex, $pattern, $matches[$name]); |
|
| 46 | + } |
|
| 43 | 47 | |
| 44 | 48 | # Process replacements |
| 45 | 49 | |
| 46 | - foreach ($source as $key => $value) if (is_scalar($value)) { |
|
| 50 | + foreach ($source as $key => $value) { |
|
| 51 | + if (is_scalar($value)) { |
|
| 47 | 52 | |
| 48 | - $output[$count] = $pattern; $item = &$output[$count++]; |
|
| 53 | + $output[$count] = $pattern; |
|
| 54 | + } |
|
| 55 | + $item = &$output[$count++]; |
|
| 49 | 56 | |
| 50 | - foreach ($matches as $name => $match) if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 57 | + foreach ($matches as $name => $match) { |
|
| 58 | + if (isset($match[1]) && isset($parsers[$match[1]])) { |
|
| 51 | 59 | |
| 52 | 60 | $item = str_replace($match[0], [$this, $parsers[$match[1]]]($$name), $item); |
| 53 | 61 | } |
| 62 | + } |
|
| 54 | 63 | }; |
| 55 | 64 | |
| 56 | 65 | # ------------------------ |
@@ -56,7 +56,9 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function getRow() { |
| 58 | 58 | |
| 59 | - if (!is_object($this->result)) return null; |
|
| 59 | + if (!is_object($this->result)) { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 60 | 62 | |
| 61 | 63 | return mysqli_fetch_assoc($this->result); |
| 62 | 64 | } |
@@ -67,9 +69,13 @@ discard block |
||
| 67 | 69 | |
| 68 | 70 | public function getRows() { |
| 69 | 71 | |
| 70 | - if (!is_object($this->result)) return []; |
|
| 72 | + if (!is_object($this->result)) { |
|
| 73 | + return []; |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | - $rows = []; while (null !== ($row = $this->getRow())) $rows[] = $row; |
|
| 76 | + $rows = []; while (null !== ($row = $this->getRow())) { |
|
| 77 | + $rows[] = $row; |
|
| 78 | + } |
|
| 73 | 79 | |
| 74 | 80 | # ------------------------ |
| 75 | 81 | |
@@ -36,7 +36,9 @@ |
||
| 36 | 36 | |
| 37 | 37 | public function addItems(array $items) { |
| 38 | 38 | |
| 39 | - foreach ($items as $item) if (is_array($item)) $this->addItem($item); |
|
| 39 | + foreach ($items as $item) { |
|
| 40 | + if (is_array($item)) $this->addItem($item); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | return $this; |
| 42 | 44 | } |
@@ -95,7 +95,9 @@ |
||
| 95 | 95 | |
| 96 | 96 | public static function output(Template\Block $block, int $status = STATUS_CODE_200) { |
| 97 | 97 | |
| 98 | - if (!Headers::isStatusCode($status)) $status = STATUS_CODE_200; |
|
| 98 | + if (!Headers::isStatusCode($status)) { |
|
| 99 | + $status = STATUS_CODE_200; |
|
| 100 | + } |
|
| 99 | 101 | |
| 100 | 102 | Headers::sendNoCache(); Headers::sendStatus($status); Headers::sendContent(MIME_TYPE_HTML); |
| 101 | 103 | |