@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param mixed $default The default value to return if the option does not exist. |
| 46 | 46 | * @return mixed |
| 47 | 47 | */ |
| 48 | - public function getOption(string $name, $default=null); |
|
| 48 | + public function getOption(string $name, $default = null); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @param string $name |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function getArrayOption(string $name) : array; |
| 55 | 55 | |
| 56 | - public function getIntOption(string $name, int $default=0) : int; |
|
| 56 | + public function getIntOption(string $name, int $default = 0) : int; |
|
| 57 | 57 | |
| 58 | - public function getBoolOption(string $name, bool $default=false) : bool; |
|
| 58 | + public function getBoolOption(string $name, bool $default = false) : bool; |
|
| 59 | 59 | |
| 60 | - public function getStringOption(string $name, string $default='') : string; |
|
| 60 | + public function getStringOption(string $name, string $default = '') : string; |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Sets a collection of options at once, from an |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | public function addLimitParam(string $name) : Request_URLComparer |
| 83 | 83 | { |
| 84 | - if(!in_array($name, $this->limitParams, true)) |
|
| 84 | + if (!in_array($name, $this->limitParams, true)) |
|
| 85 | 85 | { |
| 86 | 86 | $this->limitParams[] = $name; |
| 87 | 87 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function addLimitParams(array $names) : Request_URLComparer |
| 97 | 97 | { |
| 98 | - foreach($names as $name) |
|
| 98 | + foreach ($names as $name) |
|
| 99 | 99 | { |
| 100 | 100 | $this->addLimitParam($name); |
| 101 | 101 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | return $this; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - public function setIgnoreFragment(bool $ignore=true) : Request_URLComparer |
|
| 106 | + public function setIgnoreFragment(bool $ignore = true) : Request_URLComparer |
|
| 107 | 107 | { |
| 108 | 108 | $this->ignoreFragment = $ignore; |
| 109 | 109 | return $this; |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | 'query' |
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | - if(!$this->ignoreFragment) { |
|
| 129 | + if (!$this->ignoreFragment) { |
|
| 130 | 130 | $keys[] = 'fragment'; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - foreach($keys as $key) |
|
| 133 | + foreach ($keys as $key) |
|
| 134 | 134 | { |
| 135 | - if(!$this->compareKey($key)) { |
|
| 135 | + if (!$this->compareKey($key)) { |
|
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | $filter = 'filter_'.$key; |
| 149 | 149 | |
| 150 | - if(method_exists($this, $filter)) |
|
| 150 | + if (method_exists($this, $filter)) |
|
| 151 | 151 | { |
| 152 | 152 | $sVal = $this->$filter($sVal); |
| 153 | 153 | $tVal = $this->$filter($tVal); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | protected function filter_path(string $path) : string |
| 160 | 160 | { |
| 161 | 161 | // fix double slashes in URLs |
| 162 | - while(strpos($path, '//') !== false) |
|
| 162 | + while (strpos($path, '//') !== false) |
|
| 163 | 163 | { |
| 164 | 164 | $path = str_replace('//', '/', $path); |
| 165 | 165 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | protected function filter_query(string $query) : string |
| 171 | 171 | { |
| 172 | - if(empty($query)) { |
|
| 172 | + if (empty($query)) { |
|
| 173 | 173 | return ''; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | protected function limitParams(array $params) : array |
| 190 | 190 | { |
| 191 | - if(empty($this->limitParams)) { |
|
| 191 | + if (empty($this->limitParams)) { |
|
| 192 | 192 | return $params; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $keep = array(); |
| 196 | 196 | |
| 197 | - foreach($this->limitParams as $name) |
|
| 197 | + foreach ($this->limitParams as $name) |
|
| 198 | 198 | { |
| 199 | - if(isset($params[$name])) { |
|
| 199 | + if (isset($params[$name])) { |
|
| 200 | 200 | $keep[$name] = $params[$name]; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | * @param bool $forceNew |
| 13 | 13 | * @return NumberInfo |
| 14 | 14 | */ |
| 15 | -function parseNumber($value, bool $forceNew=false) |
|
| 15 | +function parseNumber($value, bool $forceNew = false) |
|
| 16 | 16 | { |
| 17 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
| 17 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
| 18 | 18 | return $value; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $args = func_get_args(); |
| 110 | 110 | |
| 111 | 111 | // is the localization package installed? |
| 112 | - if(function_exists('\AppLocalize\t')) |
|
| 112 | + if (function_exists('\AppLocalize\t')) |
|
| 113 | 113 | { |
| 114 | 114 | return call_user_func_array('\AppLocalize\t', $args); |
| 115 | 115 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @param bool $initial The initial boolean value to use. |
| 125 | 125 | * @return Value_Bool |
| 126 | 126 | */ |
| 127 | -function valBool(bool $initial=false) : Value_Bool |
|
| 127 | +function valBool(bool $initial = false) : Value_Bool |
|
| 128 | 128 | { |
| 129 | 129 | return new Value_Bool($initial); |
| 130 | 130 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param bool $initial |
| 138 | 138 | * @return Value_Bool_True |
| 139 | 139 | */ |
| 140 | -function valBoolTrue(bool $initial=false) : Value_Bool_True |
|
| 140 | +function valBoolTrue(bool $initial = false) : Value_Bool_True |
|
| 141 | 141 | { |
| 142 | 142 | return new Value_Bool_True($initial); |
| 143 | 143 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param bool $initial |
| 151 | 151 | * @return Value_Bool_False |
| 152 | 152 | */ |
| 153 | -function valBoolFalse(bool $initial=true) : Value_Bool_False |
|
| 153 | +function valBoolFalse(bool $initial = true) : Value_Bool_False |
|
| 154 | 154 | { |
| 155 | 155 | return new Value_Bool_False($initial); |
| 156 | 156 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | function init() : void |
| 183 | 183 | { |
| 184 | - if(!class_exists('\AppLocalize\Localization')) { |
|
| 184 | + if (!class_exists('\AppLocalize\Localization')) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param int $tabSize The amount of spaces per tab. |
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | - public static function tabs2spaces(string $string, int $tabSize=4) : string |
|
| 58 | + public static function tabs2spaces(string $string, int $tabSize = 4) : string |
|
| 59 | 59 | { |
| 60 | 60 | return ConvertHelper_String::tabs2spaces($string, $tabSize); |
| 61 | 61 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param int $tabSize The amount of spaces per tab in the source string. |
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | - public static function spaces2tabs(string $string, int $tabSize=4) : string |
|
| 70 | + public static function spaces2tabs(string $string, int $tabSize = 4) : string |
|
| 71 | 71 | { |
| 72 | 72 | return ConvertHelper_String::spaces2tabs($string, $tabSize); |
| 73 | 73 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @deprecated Use the Highlighter class directly instead. |
| 141 | 141 | * @see Highlighter::xml() |
| 142 | 142 | */ |
| 143 | - public static function highlight_xml(string $xml, bool $formatSource=false) : string |
|
| 143 | + public static function highlight_xml(string $xml, bool $formatSource = false) : string |
|
| 144 | 144 | { |
| 145 | 145 | return Highlighter::xml($xml, $formatSource); |
| 146 | 146 | } |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | * @param bool $html |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - public static function var_dump($var, bool $html=true) : string |
|
| 209 | + public static function var_dump($var, bool $html = true) : string |
|
| 210 | 210 | { |
| 211 | 211 | $info = parseVariable($var); |
| 212 | 212 | |
| 213 | - if($html) { |
|
| 213 | + if ($html) { |
|
| 214 | 214 | return $info->toHTML(); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | * @param bool $html Whether to style the dump as HTML. |
| 226 | 226 | * @return string |
| 227 | 227 | */ |
| 228 | - public static function print_r($var, bool $return=false, bool $html=true) : string |
|
| 228 | + public static function print_r($var, bool $return = false, bool $html = true) : string |
|
| 229 | 229 | { |
| 230 | 230 | $result = parseVariable($var)->enableType()->toString(); |
| 231 | 231 | |
| 232 | - if($html) |
|
| 232 | + if ($html) |
|
| 233 | 233 | { |
| 234 | 234 | $result = |
| 235 | 235 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | '</pre>'; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if(!$return) |
|
| 240 | + if (!$return) |
|
| 241 | 241 | { |
| 242 | 242 | echo $result; |
| 243 | 243 | } |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | $output = ''; |
| 420 | 420 | $split = str_split($unicodeChar); |
| 421 | 421 | |
| 422 | - foreach($split as $octet) |
|
| 422 | + foreach ($split as $octet) |
|
| 423 | 423 | { |
| 424 | 424 | $ordInt = ord($octet); |
| 425 | 425 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
| 426 | 426 | $ordHex = base_convert((string)$ordInt, 10, 16); |
| 427 | - $output .= '\x' . $ordHex; |
|
| 427 | + $output .= '\x'.$ordHex; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | return $output; |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | * |
| 639 | 639 | * @see JSHelper::buildRegexStatement() |
| 640 | 640 | */ |
| 641 | - public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) : string |
|
| 641 | + public static function regex2js(string $regex, string $statementType = JSHelper::JS_REGEX_OBJECT) : string |
|
| 642 | 642 | { |
| 643 | 643 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 644 | 644 | } |
@@ -657,11 +657,11 @@ discard block |
||
| 657 | 657 | * @throws ConvertHelper_Exception |
| 658 | 658 | * @see ConvertHelper::ERROR_JSON_ENCODE_FAILED |
| 659 | 659 | */ |
| 660 | - public static function var2json($variable, int $options=0, int $depth=512) : string |
|
| 660 | + public static function var2json($variable, int $options = 0, int $depth = 512) : string |
|
| 661 | 661 | { |
| 662 | 662 | $result = json_encode($variable, $options, $depth); |
| 663 | 663 | |
| 664 | - if($result !== false) { |
|
| 664 | + if ($result !== false) { |
|
| 665 | 665 | return $result; |
| 666 | 666 | } |
| 667 | 667 | |
@@ -701,12 +701,12 @@ discard block |
||
| 701 | 701 | { |
| 702 | 702 | $boms = FileHelper::createUnicodeHandling()->getUTFBOMs(); |
| 703 | 703 | |
| 704 | - foreach($boms as $bomChars) |
|
| 704 | + foreach ($boms as $bomChars) |
|
| 705 | 705 | { |
| 706 | 706 | $length = mb_strlen($bomChars); |
| 707 | 707 | $text = mb_substr($string, 0, $length); |
| 708 | 708 | |
| 709 | - if($text===$bomChars) |
|
| 709 | + if ($text === $bomChars) |
|
| 710 | 710 | { |
| 711 | 711 | return mb_substr($string, $length); |
| 712 | 712 | } |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * @see ConvertHelper_TextComparer::OPTION_MAX_LEVENSHTEIN_DISTANCE |
| 779 | 779 | * @see ConvertHelper_TextComparer::OPTION_PRECISION |
| 780 | 780 | */ |
| 781 | - public static function matchString(string $source, string $target, array $options=array()) : float |
|
| 781 | + public static function matchString(string $source, string $target, array $options = array()) : float |
|
| 782 | 782 | { |
| 783 | 783 | return (new ConvertHelper_TextComparer()) |
| 784 | 784 | ->setOptions($options) |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | * @see ConvertHelper::INTERVAL_HOURS |
| 857 | 857 | * @see ConvertHelper::INTERVAL_DAYS |
| 858 | 858 | */ |
| 859 | - public static function interval2total(DateInterval $interval, string $unit=self::INTERVAL_SECONDS) : int |
|
| 859 | + public static function interval2total(DateInterval $interval, string $unit = self::INTERVAL_SECONDS) : int |
|
| 860 | 860 | { |
| 861 | 861 | return ConvertHelper_DateInterval::toTotal($interval, $unit); |
| 862 | 862 | } |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * @param bool $short |
| 869 | 869 | * @return string|NULL |
| 870 | 870 | */ |
| 871 | - public static function date2dayName(DateTime $date, bool $short=false) : ?string |
|
| 871 | + public static function date2dayName(DateTime $date, bool $short = false) : ?string |
|
| 872 | 872 | { |
| 873 | 873 | return ConvertHelper_Date::toDayName($date, $short); |
| 874 | 874 | } |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | * @param bool $short |
| 889 | 889 | * @return string[] |
| 890 | 890 | */ |
| 891 | - public static function getDayNames(bool $short=false) : array |
|
| 891 | + public static function getDayNames(bool $short = false) : array |
|
| 892 | 892 | { |
| 893 | 893 | return ConvertHelper_Date::getDayNames($short); |
| 894 | 894 | } |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | * @param bool $caseInsensitive |
| 1048 | 1048 | * @return ConvertHelper_StringMatch[] |
| 1049 | 1049 | */ |
| 1050 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false): array |
|
| 1050 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false): array |
|
| 1051 | 1051 | { |
| 1052 | 1052 | return ConvertHelper_String::findString($needle, $haystack, $caseInsensitive); |
| 1053 | 1053 | } |
@@ -1097,17 +1097,17 @@ discard block |
||
| 1097 | 1097 | */ |
| 1098 | 1098 | public static function isInteger($value) : bool |
| 1099 | 1099 | { |
| 1100 | - if(is_int($value)) { |
|
| 1100 | + if (is_int($value)) { |
|
| 1101 | 1101 | return true; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | // booleans get converted to numbers, so they would |
| 1105 | 1105 | // actually match the regex. |
| 1106 | - if(is_bool($value)) { |
|
| 1106 | + if (is_bool($value)) { |
|
| 1107 | 1107 | return false; |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - if(is_string($value) && $value !== '') { |
|
| 1110 | + if (is_string($value) && $value !== '') { |
|
| 1111 | 1111 | return preg_match('/\A-?\d+\z/', $value) === 1; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | * @param bool $keepKeys |
| 1174 | 1174 | * @return array<number|string,mixed> |
| 1175 | 1175 | */ |
| 1176 | - public static function arrayRemoveValues(array $sourceArray, array $values, bool $keepKeys=false) : array |
|
| 1176 | + public static function arrayRemoveValues(array $sourceArray, array $values, bool $keepKeys = false) : array |
|
| 1177 | 1177 | { |
| 1178 | 1178 | return ConvertHelper_Array::removeValues($sourceArray, $values, $keepKeys); |
| 1179 | 1179 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. |
| 52 | 52 | $result = (float)preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. |
| 53 | 53 | |
| 54 | - if($unit) |
|
| 54 | + if ($unit) |
|
| 55 | 55 | { |
| 56 | 56 | // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. |
| 57 | 57 | return (int)round($result * (1024 ** stripos('bkmgtpezy', $unit[0]))); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param int $depth The folder depth to reduce the path to |
| 19 | 19 | * @return string |
| 20 | 20 | */ |
| 21 | - public static function relativizeByDepth(string $path, int $depth=2) : string |
|
| 21 | + public static function relativizeByDepth(string $path, int $depth = 2) : string |
|
| 22 | 22 | { |
| 23 | 23 | $path = FileHelper::normalizePath($path); |
| 24 | 24 | |
@@ -26,17 +26,17 @@ discard block |
||
| 26 | 26 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
| 27 | 27 | $tokens = array_values($tokens); // re-index keys |
| 28 | 28 | |
| 29 | - if(empty($tokens)) { |
|
| 29 | + if (empty($tokens)) { |
|
| 30 | 30 | return ''; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | // remove the drive if present |
| 34 | - if(strpos($tokens[0], ':') !== false) { |
|
| 34 | + if (strpos($tokens[0], ':') !== false) { |
|
| 35 | 35 | array_shift($tokens); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // path was only the drive |
| 39 | - if(count($tokens) === 0) { |
|
| 39 | + if (count($tokens) === 0) { |
|
| 40 | 40 | return ''; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | // reduce the path to the specified depth |
| 47 | 47 | $length = count($tokens); |
| 48 | - if($length > $depth) { |
|
| 49 | - $tokens = array_slice($tokens, $length-$depth); |
|
| 48 | + if ($length > $depth) { |
|
| 49 | + $tokens = array_slice($tokens, $length - $depth); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // append the last element again |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @see \AppUtils\FileHelper\FileFinder |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -declare(strict_types = 1); |
|
| 10 | +declare(strict_types=1); |
|
| 11 | 11 | |
| 12 | 12 | namespace AppUtils\FileHelper; |
| 13 | 13 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param bool $enabled |
| 91 | 91 | * @return FileFinder |
| 92 | 92 | */ |
| 93 | - public function makeRecursive(bool $enabled=true) : FileFinder |
|
| 93 | + public function makeRecursive(bool $enabled = true) : FileFinder |
|
| 94 | 94 | { |
| 95 | 95 | return $this->setOption('recursive', $enabled); |
| 96 | 96 | } |
@@ -295,22 +295,22 @@ discard block |
||
| 295 | 295 | return $this->getAll(); |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - protected function find(string $path, bool $isRoot=false) : void |
|
| 298 | + protected function find(string $path, bool $isRoot = false) : void |
|
| 299 | 299 | { |
| 300 | - if($isRoot) { |
|
| 300 | + if ($isRoot) { |
|
| 301 | 301 | $this->found = array(); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | $recursive = $this->getBoolOption('recursive'); |
| 305 | 305 | |
| 306 | 306 | $d = new DirectoryIterator($path); |
| 307 | - foreach($d as $item) |
|
| 307 | + foreach ($d as $item) |
|
| 308 | 308 | { |
| 309 | 309 | $pathname = $item->getPathname(); |
| 310 | 310 | |
| 311 | - if($item->isDir()) |
|
| 311 | + if ($item->isDir()) |
|
| 312 | 312 | { |
| 313 | - if($recursive && !$item->isDot()) { |
|
| 313 | + if ($recursive && !$item->isDot()) { |
|
| 314 | 314 | $this->find($pathname); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | |
| 320 | 320 | $file = $this->filterFile($pathname); |
| 321 | 321 | |
| 322 | - if($file !== null) |
|
| 322 | + if ($file !== null) |
|
| 323 | 323 | { |
| 324 | 324 | $this->found[] = $file; |
| 325 | 325 | } |
@@ -332,23 +332,23 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | $extension = FileHelper::getExtension($path); |
| 334 | 334 | |
| 335 | - if(!$this->filterExclusion($extension)) { |
|
| 335 | + if (!$this->filterExclusion($extension)) { |
|
| 336 | 336 | return null; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | $path = $this->filterPath($path); |
| 340 | 340 | |
| 341 | - if($this->getOption('strip-extensions') === true) |
|
| 341 | + if ($this->getOption('strip-extensions') === true) |
|
| 342 | 342 | { |
| 343 | 343 | $path = str_replace('.'.$extension, '', $path); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if($path === '') { |
|
| 346 | + if ($path === '') { |
|
| 347 | 347 | return null; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | $replace = $this->getOption('slash-replacement'); |
| 351 | - if(!empty($replace)) { |
|
| 351 | + if (!empty($replace)) { |
|
| 352 | 352 | $path = str_replace('/', $replace, $path); |
| 353 | 353 | } |
| 354 | 354 | |
@@ -367,13 +367,13 @@ discard block |
||
| 367 | 367 | $include = $this->getOption(self::OPTION_INCLUDE_EXTENSIONS); |
| 368 | 368 | $exclude = $this->getOption(self::OPTION_EXCLUDE_EXTENSIONS); |
| 369 | 369 | |
| 370 | - if(!empty($include)) |
|
| 370 | + if (!empty($include)) |
|
| 371 | 371 | { |
| 372 | - if(!in_array($extension, $include, true)) { |
|
| 372 | + if (!in_array($extension, $include, true)) { |
|
| 373 | 373 | return false; |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | - else if(!empty($exclude) && in_array($extension, $exclude, true)) |
|
| 376 | + else if (!empty($exclude) && in_array($extension, $exclude, true)) |
|
| 377 | 377 | { |
| 378 | 378 | return false; |
| 379 | 379 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | protected function filterPath(string $path) : string |
| 391 | 391 | { |
| 392 | - switch($this->getStringOption(self::OPTION_PATHMODE)) |
|
| 392 | + switch ($this->getStringOption(self::OPTION_PATHMODE)) |
|
| 393 | 393 | { |
| 394 | 394 | case self::PATH_MODE_STRIP: |
| 395 | 395 | return basename($path); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * @return $this |
| 125 | 125 | * @throws Request_Exception |
| 126 | 126 | */ |
| 127 | - public function setCallback(callable $callback, array $args=array()) : self |
|
| 127 | + public function setCallback(callable $callback, array $args = array()) : self |
|
| 128 | 128 | { |
| 129 | 129 | return $this->setValidation( |
| 130 | 130 | self::VALIDATION_TYPE_CALLBACK, |
@@ -149,22 +149,22 @@ discard block |
||
| 149 | 149 | // first off, apply filtering |
| 150 | 150 | $value = $this->filter($value); |
| 151 | 151 | |
| 152 | - if($this->valueType === self::VALUE_TYPE_LIST) |
|
| 152 | + if ($this->valueType === self::VALUE_TYPE_LIST) |
|
| 153 | 153 | { |
| 154 | - if(!is_array($value)) |
|
| 154 | + if (!is_array($value)) |
|
| 155 | 155 | { |
| 156 | 156 | $value = explode(',', $value); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $keep = array(); |
| 160 | 160 | |
| 161 | - foreach($value as $subval) |
|
| 161 | + foreach ($value as $subval) |
|
| 162 | 162 | { |
| 163 | 163 | $subval = $this->filter($subval); |
| 164 | 164 | |
| 165 | 165 | $subval = $this->applyValidations($subval, true); |
| 166 | 166 | |
| 167 | - if($subval !== null) { |
|
| 167 | + if ($subval !== null) { |
|
| 168 | 168 | $keep[] = $subval; |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @param mixed $value |
| 184 | 184 | * @return mixed |
| 185 | 185 | */ |
| 186 | - protected function applyValidations($value, bool $subval=false) |
|
| 186 | + protected function applyValidations($value, bool $subval = false) |
|
| 187 | 187 | { |
| 188 | 188 | // go through all enqueued validations in turn, each time |
| 189 | 189 | // replacing the value with the adjusted, validated value. |
| 190 | - foreach($this->validations as $validateDef) |
|
| 190 | + foreach ($this->validations as $validateDef) |
|
| 191 | 191 | { |
| 192 | 192 | $value = $this->validateType($value, $validateDef['type'], $validateDef['params'], $subval); |
| 193 | 193 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | $class = Request_Param_Validator::class.'_'.ucfirst($type); |
| 212 | 212 | |
| 213 | - if(!class_exists($class)) |
|
| 213 | + if (!class_exists($class)) |
|
| 214 | 214 | { |
| 215 | 215 | throw new Request_Exception( |
| 216 | 216 | 'Unknown validation type.', |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | $args = func_get_args(); // cannot be used as function parameter in some PHP versions |
| 363 | 363 | |
| 364 | - if(is_array($args[0])) |
|
| 364 | + if (is_array($args[0])) |
|
| 365 | 365 | { |
| 366 | 366 | $args = $args[0]; |
| 367 | 367 | } |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | * @param mixed $default |
| 512 | 512 | * @return mixed |
| 513 | 513 | */ |
| 514 | - public function get($default=null) |
|
| 514 | + public function get($default = null) |
|
| 515 | 515 | { |
| 516 | 516 | $value = $this->request->getParam($this->paramName); |
| 517 | - if($value !== null && $value !== '') { |
|
| 517 | + if ($value !== null && $value !== '') { |
|
| 518 | 518 | return $value; |
| 519 | 519 | } |
| 520 | 520 | |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | { |
| 539 | 539 | foreach ($this->filters as $filter) |
| 540 | 540 | { |
| 541 | - $method = 'applyFilter_' . $filter['type']; |
|
| 541 | + $method = 'applyFilter_'.$filter['type']; |
|
| 542 | 542 | $value = $this->$method($value, $filter['params']); |
| 543 | 543 | } |
| 544 | 544 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | |
| 558 | 558 | $filter = new $class($this); |
| 559 | 559 | |
| 560 | - if($filter instanceof Request_Param_Filter) |
|
| 560 | + if ($filter instanceof Request_Param_Filter) |
|
| 561 | 561 | { |
| 562 | 562 | $filter->setOptions($config['params']); |
| 563 | 563 | return $filter->filter($value); |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
| 717 | 717 | * @return $this |
| 718 | 718 | */ |
| 719 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : self |
|
| 719 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : self |
|
| 720 | 720 | { |
| 721 | 721 | $this->setArray(); |
| 722 | 722 | |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | * @return $this |
| 736 | 736 | * @throws Request_Exception |
| 737 | 737 | */ |
| 738 | - protected function addClassFilter(string $name, array $params=array()) : self |
|
| 738 | + protected function addClassFilter(string $name, array $params = array()) : self |
|
| 739 | 739 | { |
| 740 | 740 | return $this->addFilter( |
| 741 | 741 | self::FILTER_TYPE_CLASS, |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $value = $_REQUEST[$name] ?? $default; |
| 93 | 93 | |
| 94 | - if(isset($this->knownParams[$name])) { |
|
| 94 | + if (isset($this->knownParams[$name])) { |
|
| 95 | 95 | $value = $this->knownParams[$name]->validate($value); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - public function buildURL(array $params = array(), string $dispatcher='') : string |
|
| 191 | + public function buildURL(array $params = array(), string $dispatcher = '') : string |
|
| 192 | 192 | { |
| 193 | - $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher; |
|
| 193 | + $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher; |
|
| 194 | 194 | |
| 195 | 195 | // append any leftover parameters to the end of the URL |
| 196 | 196 | if (!empty($params)) { |
| 197 | - $url .= '?' . http_build_query($params, '', '&'); |
|
| 197 | + $url .= '?'.http_build_query($params, '', '&'); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $url; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function registerParam(string $name) : RequestParam |
| 227 | 227 | { |
| 228 | - if(!isset($this->knownParams[$name])) { |
|
| 228 | + if (!isset($this->knownParams[$name])) { |
|
| 229 | 229 | $param = new RequestParam($this, $name); |
| 230 | 230 | $this->knownParams[$name] = $param; |
| 231 | 231 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | public function getRegisteredParam(string $name) : RequestParam |
| 244 | 244 | { |
| 245 | - if(isset($this->knownParams[$name])) { |
|
| 245 | + if (isset($this->knownParams[$name])) { |
|
| 246 | 246 | return $this->knownParams[$name]; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | { |
| 303 | 303 | static $accept; |
| 304 | 304 | |
| 305 | - if(!isset($accept)) { |
|
| 305 | + if (!isset($accept)) { |
|
| 306 | 306 | $accept = new Request_AcceptHeaders(); |
| 307 | 307 | } |
| 308 | 308 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | { |
| 322 | 322 | $_REQUEST[$name] = $value; |
| 323 | 323 | |
| 324 | - if(isset($this->knownParams[$name])) { |
|
| 324 | + if (isset($this->knownParams[$name])) { |
|
| 325 | 325 | unset($this->knownParams[$name]); |
| 326 | 326 | } |
| 327 | 327 | |
@@ -351,11 +351,11 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | public function removeParam(string $name) : Request |
| 353 | 353 | { |
| 354 | - if(isset($_REQUEST[$name])) { |
|
| 354 | + if (isset($_REQUEST[$name])) { |
|
| 355 | 355 | unset($_REQUEST[$name]); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - if(isset($this->knownParams[$name])) { |
|
| 358 | + if (isset($this->knownParams[$name])) { |
|
| 359 | 359 | unset($this->knownParams[$name]); |
| 360 | 360 | } |
| 361 | 361 | |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | public function removeParams(array $names) : Request |
| 372 | 372 | { |
| 373 | - foreach($names as $name) { |
|
| 373 | + foreach ($names as $name) { |
|
| 374 | 374 | $this->removeParam($name); |
| 375 | 375 | } |
| 376 | 376 | |
@@ -388,11 +388,11 @@ discard block |
||
| 388 | 388 | * @return bool |
| 389 | 389 | * @throws ConvertHelper_Exception |
| 390 | 390 | */ |
| 391 | - public function getBool(string $name, bool $default=false) : bool |
|
| 391 | + public function getBool(string $name, bool $default = false) : bool |
|
| 392 | 392 | { |
| 393 | 393 | $value = $this->getParam($name, $default); |
| 394 | 394 | |
| 395 | - if(ConvertHelper::isBoolean($value)) { |
|
| 395 | + if (ConvertHelper::isBoolean($value)) { |
|
| 396 | 396 | return ConvertHelper::string2bool($value); |
| 397 | 397 | } |
| 398 | 398 | |
@@ -401,11 +401,11 @@ discard block |
||
| 401 | 401 | |
| 402 | 402 | public function validate() : void |
| 403 | 403 | { |
| 404 | - foreach($this->knownParams as $param) |
|
| 404 | + foreach ($this->knownParams as $param) |
|
| 405 | 405 | { |
| 406 | 406 | $name = $param->getName(); |
| 407 | 407 | |
| 408 | - if($param->isRequired() && !$this->hasParam($name)) |
|
| 408 | + if ($param->isRequired() && !$this->hasParam($name)) |
|
| 409 | 409 | { |
| 410 | 410 | throw new Request_Exception( |
| 411 | 411 | 'Missing request parameter '.$name, |
@@ -427,26 +427,26 @@ discard block |
||
| 427 | 427 | * @param mixed $default |
| 428 | 428 | * @return mixed |
| 429 | 429 | */ |
| 430 | - public function getFilteredParam(string $name, $default=null) |
|
| 430 | + public function getFilteredParam(string $name, $default = null) |
|
| 431 | 431 | { |
| 432 | 432 | $val = $this->getParam($name, $default); |
| 433 | 433 | |
| 434 | - if(is_string($val)) |
|
| 434 | + if (is_string($val)) |
|
| 435 | 435 | { |
| 436 | 436 | return htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - if(is_bool($val)) |
|
| 439 | + if (is_bool($val)) |
|
| 440 | 440 | { |
| 441 | 441 | return ConvertHelper::boolStrict2string($val); |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if(is_numeric($val)) |
|
| 444 | + if (is_numeric($val)) |
|
| 445 | 445 | { |
| 446 | 446 | return (string)$val; |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - if(is_null($val)) |
|
| 449 | + if (is_null($val)) |
|
| 450 | 450 | { |
| 451 | 451 | return ''; |
| 452 | 452 | } |
@@ -466,11 +466,11 @@ discard block |
||
| 466 | 466 | * @see Request::getJSONObject() |
| 467 | 467 | * @see Request::getJSONAssoc() |
| 468 | 468 | */ |
| 469 | - public function getJSON(string $name, bool $assoc=true) |
|
| 469 | + public function getJSON(string $name, bool $assoc = true) |
|
| 470 | 470 | { |
| 471 | 471 | $value = $this->getParam($name); |
| 472 | 472 | |
| 473 | - if(!empty($value) && is_string($value)) |
|
| 473 | + if (!empty($value) && is_string($value)) |
|
| 474 | 474 | { |
| 475 | 475 | try |
| 476 | 476 | { |
@@ -481,16 +481,16 @@ discard block |
||
| 481 | 481 | return array(); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if($assoc && is_array($data)) { |
|
| 484 | + if ($assoc && is_array($data)) { |
|
| 485 | 485 | return $data; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if(is_object($data)) { |
|
| 488 | + if (is_object($data)) { |
|
| 489 | 489 | return $data; |
| 490 | 490 | } |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - if($assoc) { |
|
| 493 | + if ($assoc) { |
|
| 494 | 494 | return array(); |
| 495 | 495 | } |
| 496 | 496 | |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | public function getJSONAssoc(string $name) : array |
| 508 | 508 | { |
| 509 | 509 | $result = $this->getJSON($name); |
| 510 | - if(is_array($result)) { |
|
| 510 | + if (is_array($result)) { |
|
| 511 | 511 | return $result; |
| 512 | 512 | } |
| 513 | 513 | |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | public function getJSONObject(string $name) : object |
| 525 | 525 | { |
| 526 | 526 | $result = $this->getJSON($name, false); |
| 527 | - if(is_object($result)) { |
|
| 527 | + if (is_object($result)) { |
|
| 528 | 528 | return $result; |
| 529 | 529 | } |
| 530 | 530 | |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | { |
| 542 | 542 | $payload = $data; |
| 543 | 543 | |
| 544 | - if(!is_string($payload)) { |
|
| 544 | + if (!is_string($payload)) { |
|
| 545 | 545 | $payload = json_encode($payload, JSON_THROW_ON_ERROR); |
| 546 | 546 | } |
| 547 | 547 | |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | * @param string[] $limitParams Whether to limit the comparison to these specific parameter names (if present) |
| 599 | 599 | * @return Request_URLComparer |
| 600 | 600 | */ |
| 601 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
| 601 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
| 602 | 602 | { |
| 603 | 603 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
| 604 | 604 | $comparer->addLimitParams($limitParams); |