@@ -55,8 +55,7 @@ |
||
| 55 | 55 | if(is_array($serialized)) |
| 56 | 56 | { |
| 57 | 57 | $this->parseSerialized($serialized); |
| 58 | - } |
|
| 59 | - else |
|
| 58 | + } else |
|
| 60 | 59 | { |
| 61 | 60 | $this->parseValue($value); |
| 62 | 61 | } |
@@ -32,25 +32,25 @@ discard block |
||
| 32 | 32 | self::TYPE_CALLABLE => 'cf5e20' |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | 38 | protected $string; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var mixed |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var mixed |
|
| 42 | + */ |
|
| 43 | 43 | protected $value; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $type; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param mixed $value |
|
| 52 | - * @param array|null $serialized |
|
| 53 | - */ |
|
| 50 | + /** |
|
| 51 | + * @param mixed $value |
|
| 52 | + * @param array|null $serialized |
|
| 53 | + */ |
|
| 54 | 54 | public function __construct($value, $serialized=null) |
| 55 | 55 | { |
| 56 | 56 | if(is_array($serialized)) |
@@ -63,26 +63,26 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Creates a new variable info instance from a PHP variable |
|
| 68 | - * of any type. |
|
| 69 | - * |
|
| 70 | - * @param mixed $variable |
|
| 71 | - * @return VariableInfo |
|
| 72 | - */ |
|
| 66 | + /** |
|
| 67 | + * Creates a new variable info instance from a PHP variable |
|
| 68 | + * of any type. |
|
| 69 | + * |
|
| 70 | + * @param mixed $variable |
|
| 71 | + * @return VariableInfo |
|
| 72 | + */ |
|
| 73 | 73 | public static function fromVariable($variable) : VariableInfo |
| 74 | 74 | { |
| 75 | 75 | return new VariableInfo($variable); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Restores a variable info instance using a previously serialized |
|
| 80 | - * array using the serialize() method. |
|
| 81 | - * |
|
| 82 | - * @param array $serialized |
|
| 83 | - * @return VariableInfo |
|
| 84 | - * @see VariableInfo::serialize() |
|
| 85 | - */ |
|
| 78 | + /** |
|
| 79 | + * Restores a variable info instance using a previously serialized |
|
| 80 | + * array using the serialize() method. |
|
| 81 | + * |
|
| 82 | + * @param array $serialized |
|
| 83 | + * @return VariableInfo |
|
| 84 | + * @see VariableInfo::serialize() |
|
| 85 | + */ |
|
| 86 | 86 | public static function fromSerialized(array $serialized) : VariableInfo |
| 87 | 87 | { |
| 88 | 88 | return new VariableInfo(null, $serialized); |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | $this->string = $this->_toString(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * The variable type - this is the same string that |
|
| 113 | - * is returned by the PHP function `gettype`. |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 111 | + /** |
|
| 112 | + * The variable type - this is the same string that |
|
| 113 | + * is returned by the PHP function `gettype`. |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | 117 | public function getType() : string |
| 118 | 118 | { |
| 119 | 119 | return $this->type; |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | ); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Whether to prepend the variable type before the value, |
|
| 132 | - * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 133 | - * |
|
| 134 | - * @param bool $enable |
|
| 135 | - * @return VariableInfo |
|
| 136 | - */ |
|
| 130 | + /** |
|
| 131 | + * Whether to prepend the variable type before the value, |
|
| 132 | + * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 133 | + * |
|
| 134 | + * @param bool $enable |
|
| 135 | + * @return VariableInfo |
|
| 136 | + */ |
|
| 137 | 137 | public function enableType(bool $enable=true) : VariableInfo |
| 138 | 138 | { |
| 139 | 139 | return $this->setOption('prepend-type', $enable); |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | return $converted; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Converts an array to a string. |
|
| 208 | - * @return string |
|
| 209 | - * |
|
| 210 | - * @todo Create custom dump implementation, using VariableInfo instances. |
|
| 211 | - */ |
|
| 206 | + /** |
|
| 207 | + * Converts an array to a string. |
|
| 208 | + * @return string |
|
| 209 | + * |
|
| 210 | + * @todo Create custom dump implementation, using VariableInfo instances. |
|
| 211 | + */ |
|
| 212 | 212 | protected function toString_array() : string |
| 213 | 213 | { |
| 214 | 214 | $result = json_encode($this->value, JSON_PRETTY_PRINT); |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @param mixed $value |
| 52 | 52 | * @param array|null $serialized |
| 53 | 53 | */ |
| 54 | - public function __construct($value, $serialized=null) |
|
| 54 | + public function __construct($value, $serialized = null) |
|
| 55 | 55 | { |
| 56 | - if(is_array($serialized)) |
|
| 56 | + if (is_array($serialized)) |
|
| 57 | 57 | { |
| 58 | 58 | $this->parseSerialized($serialized); |
| 59 | 59 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->value = $value; |
| 102 | 102 | $this->type = strtolower(gettype($value)); |
| 103 | 103 | |
| 104 | - if(is_array($value) && is_callable($value)) { |
|
| 104 | + if (is_array($value) && is_callable($value)) { |
|
| 105 | 105 | $this->type = self::TYPE_CALLABLE; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param bool $enable |
| 135 | 135 | * @return VariableInfo |
| 136 | 136 | */ |
| 137 | - public function enableType(bool $enable=true) : VariableInfo |
|
| 137 | + public function enableType(bool $enable = true) : VariableInfo |
|
| 138 | 138 | { |
| 139 | 139 | return $this->setOption('prepend-type', $enable); |
| 140 | 140 | } |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $converted = $this->string; |
| 145 | 145 | |
| 146 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 146 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 147 | 147 | { |
| 148 | - if($this->isString()) |
|
| 148 | + if ($this->isString()) |
|
| 149 | 149 | { |
| 150 | 150 | $converted = '"'.$converted.'"'; |
| 151 | 151 | } |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $converted = $this->$varMethod(); |
| 179 | 179 | |
| 180 | - if($format === 'HTML') |
|
| 180 | + if ($format === 'HTML') |
|
| 181 | 181 | { |
| 182 | 182 | $converted = '<span style="color:#'.self::$colors[$type].'" class="variable-value-'.$this->type.'">'.$converted.'</span>'; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 185 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 186 | 186 | { |
| 187 | 187 | $typeLabel = $type; |
| 188 | 188 | |
| 189 | - switch($format) |
|
| 189 | + switch ($format) |
|
| 190 | 190 | { |
| 191 | 191 | case 'HTML': |
| 192 | 192 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$type.'</span> '; |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | // the array may not be encodable - for example if it contains |
| 217 | 217 | // broken unicode characters. |
| 218 | - if(is_string($result) && $result !== '') { |
|
| 218 | + if (is_string($result) && $result !== '') { |
|
| 219 | 219 | return $result; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $string = ''; |
| 228 | 228 | |
| 229 | - if(is_string($this->value[0])) { |
|
| 229 | + if (is_string($this->value[0])) { |
|
| 230 | 230 | $string .= $this->value[0].'::'; |
| 231 | 231 | } else { |
| 232 | 232 | $string .= get_class($this->value[0]).'->'; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | str_replace(' ', '-', $this->type) |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 356 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 357 | 357 | { |
| 358 | 358 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->type.'</span> '; |
| 359 | 359 | $converted = $typeLabel.' '.$converted; |
@@ -59,8 +59,7 @@ discard block |
||
| 59 | 59 | try |
| 60 | 60 | { |
| 61 | 61 | throw new BaseException(''); |
| 62 | - } |
|
| 63 | - catch(BaseException $e) |
|
| 62 | + } catch(BaseException $e) |
|
| 64 | 63 | { |
| 65 | 64 | echo self::createInfo($e)->toString(); |
| 66 | 65 | } |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | try |
| 75 | 74 | { |
| 76 | 75 | throw new BaseException(''); |
| 77 | - } |
|
| 78 | - catch(BaseException $e) |
|
| 76 | + } catch(BaseException $e) |
|
| 79 | 77 | { |
| 80 | 78 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 81 | 79 | echo self::createInfo($e)->toString(); |
@@ -20,17 +20,17 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class BaseException extends \Exception |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $details; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $message |
|
| 30 | - * @param string $details |
|
| 31 | - * @param int $code |
|
| 32 | - * @param \Exception $previous |
|
| 33 | - */ |
|
| 28 | + /** |
|
| 29 | + * @param string $message |
|
| 30 | + * @param string $details |
|
| 31 | + * @param int $code |
|
| 32 | + * @param \Exception $previous |
|
| 33 | + */ |
|
| 34 | 34 | public function __construct(string $message, $details=null, $code=null, $previous=null) |
| 35 | 35 | { |
| 36 | 36 | parent::__construct($message, $code, $previous); |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | $this->details = $details; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Retrieves the detailed error description, if any. |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 41 | + /** |
|
| 42 | + * Retrieves the detailed error description, if any. |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | 45 | public function getDetails() : string |
| 46 | 46 | { |
| 47 | 47 | if($this->details !== null) { |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Displays pertinent information on the exception in |
|
| 56 | - * the browser, and exits the script. |
|
| 57 | - */ |
|
| 54 | + /** |
|
| 55 | + * Displays pertinent information on the exception in |
|
| 56 | + * the browser, and exits the script. |
|
| 57 | + */ |
|
| 58 | 58 | public function display() |
| 59 | 59 | { |
| 60 | 60 | if(!headers_sent()) { |
@@ -65,20 +65,20 @@ discard block |
||
| 65 | 65 | exit; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Retrieves information on the exception that can be |
|
| 70 | - * easily accessed. |
|
| 71 | - * |
|
| 72 | - * @return ConvertHelper_ThrowableInfo |
|
| 73 | - */ |
|
| 68 | + /** |
|
| 69 | + * Retrieves information on the exception that can be |
|
| 70 | + * easily accessed. |
|
| 71 | + * |
|
| 72 | + * @return ConvertHelper_ThrowableInfo |
|
| 73 | + */ |
|
| 74 | 74 | public function getInfo() : ConvertHelper_ThrowableInfo |
| 75 | 75 | { |
| 76 | 76 | return ConvertHelper::throwable2info($this); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Dumps a current PHP function trace, as a textonly string. |
|
| 81 | - */ |
|
| 79 | + /** |
|
| 80 | + * Dumps a current PHP function trace, as a textonly string. |
|
| 81 | + */ |
|
| 82 | 82 | public static function dumpTraceAsString() |
| 83 | 83 | { |
| 84 | 84 | try |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Dumps a current PHP function trace, with HTML styling. |
|
| 96 | - */ |
|
| 94 | + /** |
|
| 95 | + * Dumps a current PHP function trace, with HTML styling. |
|
| 96 | + */ |
|
| 97 | 97 | public static function dumpTraceAsHTML() |
| 98 | 98 | { |
| 99 | 99 | try |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Creates an exception info instance from a throwable instance. |
|
| 113 | - * |
|
| 114 | - * @param \Throwable $e |
|
| 115 | - * @return ConvertHelper_ThrowableInfo |
|
| 116 | - * @see ConvertHelper::throwable2info() |
|
| 117 | - */ |
|
| 111 | + /** |
|
| 112 | + * Creates an exception info instance from a throwable instance. |
|
| 113 | + * |
|
| 114 | + * @param \Throwable $e |
|
| 115 | + * @return ConvertHelper_ThrowableInfo |
|
| 116 | + * @see ConvertHelper::throwable2info() |
|
| 117 | + */ |
|
| 118 | 118 | public static function createInfo(\Throwable $e) : ConvertHelper_ThrowableInfo |
| 119 | 119 | { |
| 120 | 120 | return ConvertHelper::throwable2info($e); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param int $code |
| 32 | 32 | * @param \Exception $previous |
| 33 | 33 | */ |
| 34 | - public function __construct(string $message, $details=null, $code=null, $previous=null) |
|
| 34 | + public function __construct(string $message, $details = null, $code = null, $previous = null) |
|
| 35 | 35 | { |
| 36 | 36 | parent::__construct($message, $code, $previous); |
| 37 | 37 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getDetails() : string |
| 46 | 46 | { |
| 47 | - if($this->details !== null) { |
|
| 47 | + if ($this->details !== null) { |
|
| 48 | 48 | return $this->details; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function display() |
| 59 | 59 | { |
| 60 | - if(!headers_sent()) { |
|
| 60 | + if (!headers_sent()) { |
|
| 61 | 61 | header('Content-type:text/plain; charset=utf-8'); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | throw new BaseException(''); |
| 87 | 87 | } |
| 88 | - catch(BaseException $e) |
|
| 88 | + catch (BaseException $e) |
|
| 89 | 89 | { |
| 90 | 90 | echo self::createInfo($e)->toString(); |
| 91 | 91 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | throw new BaseException(''); |
| 102 | 102 | } |
| 103 | - catch(BaseException $e) |
|
| 103 | + catch (BaseException $e) |
|
| 104 | 104 | { |
| 105 | 105 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 106 | 106 | echo self::createInfo($e)->toString(); |
@@ -38,38 +38,38 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | protected $text; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | 44 | protected $trimmed; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var int |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var int |
|
| 48 | + */ |
|
| 49 | 49 | protected $lineNumber; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | 54 | protected $type; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | 59 | protected $varName = ''; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | 64 | protected $varValue = ''; |
| 65 | 65 | |
| 66 | 66 | protected $valueUnquoted = ''; |
| 67 | 67 | |
| 68 | 68 | protected $quoteStyle = ''; |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 70 | + /** |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | 73 | protected $sectionName = ''; |
| 74 | 74 | |
| 75 | 75 | public function __construct(string $text, int $lineNumber) |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $this->trimmed = trim($text); |
| 79 | 79 | $this->lineNumber = $lineNumber; |
| 80 | 80 | |
| 81 | - if(empty($this->trimmed)) |
|
| 81 | + if (empty($this->trimmed)) |
|
| 82 | 82 | { |
| 83 | 83 | $this->type = self::TYPE_EMPTY; |
| 84 | 84 | return; |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $startChar = substr($this->trimmed, 0, 1); |
| 88 | 88 | |
| 89 | - if($startChar === ';') |
|
| 89 | + if ($startChar === ';') |
|
| 90 | 90 | { |
| 91 | 91 | $this->type = self::TYPE_COMMENT; |
| 92 | 92 | } |
| 93 | - else if($startChar === '[') |
|
| 93 | + else if ($startChar === '[') |
|
| 94 | 94 | { |
| 95 | 95 | $this->type = self::TYPE_SECTION_DECLARATION; |
| 96 | 96 | $this->sectionName = trim($this->trimmed, '[]'); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | else |
| 100 | 100 | { |
| 101 | 101 | $pos = strpos($this->trimmed, '='); |
| 102 | - if($pos === false) |
|
| 102 | + if ($pos === false) |
|
| 103 | 103 | { |
| 104 | 104 | $this->type = self::TYPE_INVALID; |
| 105 | 105 | return; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->type = self::TYPE_VALUE; |
| 109 | 109 | $this->varName = trim(substr($this->trimmed, 0, $pos)); |
| 110 | 110 | |
| 111 | - $this->parseValue(substr($this->trimmed, $pos+1)); |
|
| 111 | + $this->parseValue(substr($this->trimmed, $pos + 1)); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $value = $this->varValue; |
| 120 | 120 | |
| 121 | - if(substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
| 121 | + if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
| 122 | 122 | { |
| 123 | 123 | $value = trim($value, '"'); |
| 124 | 124 | $this->quoteStyle = '"'; |
| 125 | 125 | } |
| 126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 126 | + else if (substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 127 | 127 | { |
| 128 | 128 | $value = trim($value, "'"); |
| 129 | 129 | $this->quoteStyle = "'"; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public function getQuotedVarValue() : string |
| 146 | 146 | { |
| 147 | - if($this->quoteStyle === '') { |
|
| 147 | + if ($this->quoteStyle === '') { |
|
| 148 | 148 | return $this->getVarValue(); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | public function setValue($value) : IniHelper_Line |
| 200 | 200 | { |
| 201 | - if(!is_scalar($value)) |
|
| 201 | + if (!is_scalar($value)) |
|
| 202 | 202 | { |
| 203 | 203 | throw new IniHelper_Exception( |
| 204 | 204 | 'Cannot use non-scalar values.', |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | public function toString() : string |
| 220 | 220 | { |
| 221 | - switch($this->type) |
|
| 221 | + switch ($this->type) |
|
| 222 | 222 | { |
| 223 | 223 | case self::TYPE_EMPTY: |
| 224 | 224 | case self::TYPE_INVALID: |
@@ -89,14 +89,12 @@ discard block |
||
| 89 | 89 | if($startChar === ';') |
| 90 | 90 | { |
| 91 | 91 | $this->type = self::TYPE_COMMENT; |
| 92 | - } |
|
| 93 | - else if($startChar === '[') |
|
| 92 | + } else if($startChar === '[') |
|
| 94 | 93 | { |
| 95 | 94 | $this->type = self::TYPE_SECTION_DECLARATION; |
| 96 | 95 | $this->sectionName = trim($this->trimmed, '[]'); |
| 97 | 96 | $this->sectionName = trim($this->sectionName); // remove any whitespace |
| 98 | - } |
|
| 99 | - else |
|
| 97 | + } else |
|
| 100 | 98 | { |
| 101 | 99 | $pos = strpos($this->trimmed, '='); |
| 102 | 100 | if($pos === false) |
@@ -122,8 +120,7 @@ discard block |
||
| 122 | 120 | { |
| 123 | 121 | $value = trim($value, '"'); |
| 124 | 122 | $this->quoteStyle = '"'; |
| 125 | - } |
|
| 126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 123 | + } else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
| 127 | 124 | { |
| 128 | 125 | $value = trim($value, "'"); |
| 129 | 126 | $this->quoteStyle = "'"; |
@@ -21,19 +21,19 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class IniHelper_Section |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var IniHelper |
|
| 26 | - */ |
|
| 24 | + /** |
|
| 25 | + * @var IniHelper |
|
| 26 | + */ |
|
| 27 | 27 | protected $ini; |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | 32 | protected $name; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var IniHelper_Line[] |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var IniHelper_Line[] |
|
| 36 | + */ |
|
| 37 | 37 | protected $lines = array(); |
| 38 | 38 | |
| 39 | 39 | public function __construct(IniHelper $ini, string $name) |
@@ -42,33 +42,33 @@ discard block |
||
| 42 | 42 | $this->name = $name; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * The section's name. |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 45 | + /** |
|
| 46 | + * The section's name. |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | 49 | public function getName() : string |
| 50 | 50 | { |
| 51 | 51 | return $this->name; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Whether this is the default section: this |
|
| 56 | - * is used internally to store all variables that |
|
| 57 | - * are not in any specific section. |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 54 | + /** |
|
| 55 | + * Whether this is the default section: this |
|
| 56 | + * is used internally to store all variables that |
|
| 57 | + * are not in any specific section. |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | 61 | public function isDefault() : bool |
| 62 | 62 | { |
| 63 | 63 | return $this->name === IniHelper::SECTION_DEFAULT; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Adds a line instance to the section. |
|
| 68 | - * |
|
| 69 | - * @param IniHelper_Line $line |
|
| 70 | - * @return IniHelper_Section |
|
| 71 | - */ |
|
| 66 | + /** |
|
| 67 | + * Adds a line instance to the section. |
|
| 68 | + * |
|
| 69 | + * @param IniHelper_Line $line |
|
| 70 | + * @return IniHelper_Section |
|
| 71 | + */ |
|
| 72 | 72 | public function addLine(IniHelper_Line $line) : IniHelper_Section |
| 73 | 73 | { |
| 74 | 74 | $this->lines[] = $line; |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Converts the values contained in the section into |
|
| 81 | - * an associative array. |
|
| 82 | - * |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 79 | + /** |
|
| 80 | + * Converts the values contained in the section into |
|
| 81 | + * an associative array. |
|
| 82 | + * |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | 85 | public function toArray() : array |
| 86 | 86 | { |
| 87 | 87 | $result = array(); |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | return $result; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Converts the section's lines into an INI string. |
|
| 119 | - * |
|
| 120 | - * @return string |
|
| 121 | - */ |
|
| 117 | + /** |
|
| 118 | + * Converts the section's lines into an INI string. |
|
| 119 | + * |
|
| 120 | + * @return string |
|
| 121 | + */ |
|
| 122 | 122 | public function toString() |
| 123 | 123 | { |
| 124 | 124 | $lines = array(); |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | return implode($this->ini->getEOLChar(), $lines); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Deletes a line from the section. |
|
| 145 | - * |
|
| 146 | - * @param IniHelper_Line $toDelete |
|
| 147 | - * @return IniHelper_Section |
|
| 148 | - */ |
|
| 143 | + /** |
|
| 144 | + * Deletes a line from the section. |
|
| 145 | + * |
|
| 146 | + * @param IniHelper_Line $toDelete |
|
| 147 | + * @return IniHelper_Section |
|
| 148 | + */ |
|
| 149 | 149 | public function deleteLine(IniHelper_Line $toDelete) : IniHelper_Section |
| 150 | 150 | { |
| 151 | 151 | $keep = array(); |
@@ -162,13 +162,13 @@ discard block |
||
| 162 | 162 | return $this; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Sets the value of a variable, overwriting any existing value. |
|
| 167 | - * |
|
| 168 | - * @param string $name |
|
| 169 | - * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
| 170 | - * @return IniHelper_Section |
|
| 171 | - */ |
|
| 165 | + /** |
|
| 166 | + * Sets the value of a variable, overwriting any existing value. |
|
| 167 | + * |
|
| 168 | + * @param string $name |
|
| 169 | + * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
| 170 | + * @return IniHelper_Section |
|
| 171 | + */ |
|
| 172 | 172 | public function setValue(string $name, $value) : IniHelper_Section |
| 173 | 173 | { |
| 174 | 174 | $lines = $this->getLinesByVariable($name); |
@@ -229,15 +229,15 @@ discard block |
||
| 229 | 229 | return $this; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Adds a variable value to the section. Unlike setValue(), this |
|
| 234 | - * will not overwrite any existing value. If the name is an existing |
|
| 235 | - * variable name, it will be converted to duplicate keys. |
|
| 236 | - * |
|
| 237 | - * @param string $name |
|
| 238 | - * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 239 | - * @return IniHelper_Section |
|
| 240 | - */ |
|
| 232 | + /** |
|
| 233 | + * Adds a variable value to the section. Unlike setValue(), this |
|
| 234 | + * will not overwrite any existing value. If the name is an existing |
|
| 235 | + * variable name, it will be converted to duplicate keys. |
|
| 236 | + * |
|
| 237 | + * @param string $name |
|
| 238 | + * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
| 239 | + * @return IniHelper_Section |
|
| 240 | + */ |
|
| 241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
| 242 | 242 | { |
| 243 | 243 | // array value? Treat it as duplicate keys. |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Retrieves all lines for the specified variable name. |
|
| 300 | - * |
|
| 301 | - * @param string $name |
|
| 302 | - * @return \AppUtils\IniHelper_Line[] |
|
| 303 | - */ |
|
| 298 | + /** |
|
| 299 | + * Retrieves all lines for the specified variable name. |
|
| 300 | + * |
|
| 301 | + * @param string $name |
|
| 302 | + * @return \AppUtils\IniHelper_Line[] |
|
| 303 | + */ |
|
| 304 | 304 | public function getLinesByVariable(string $name) |
| 305 | 305 | { |
| 306 | 306 | $result = array(); |
@@ -86,15 +86,15 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | $result = array(); |
| 88 | 88 | |
| 89 | - foreach($this->lines as $line) |
|
| 89 | + foreach ($this->lines as $line) |
|
| 90 | 90 | { |
| 91 | - if(!$line->isValue()) { |
|
| 91 | + if (!$line->isValue()) { |
|
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $name = $line->getVarName(); |
| 96 | 96 | |
| 97 | - if(!isset($result[$name])) |
|
| 97 | + if (!isset($result[$name])) |
|
| 98 | 98 | { |
| 99 | 99 | $result[$name] = $line->getVarValue(); |
| 100 | 100 | continue; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | // name exists in collection? Then this is a |
| 104 | 104 | // duplicate key and we need to convert it to |
| 105 | 105 | // an indexed array of values. |
| 106 | - if(!is_array($result[$name])) |
|
| 106 | + if (!is_array($result[$name])) |
|
| 107 | 107 | { |
| 108 | 108 | $result[$name] = array($result[$name]); |
| 109 | 109 | } |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | public function toString() |
| 123 | 123 | { |
| 124 | 124 | $lines = array(); |
| 125 | - if(!$this->isDefault()) |
|
| 125 | + if (!$this->isDefault()) |
|
| 126 | 126 | { |
| 127 | 127 | $lines[] = '['.$this->getName().']'; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - foreach($this->lines as $line) |
|
| 130 | + foreach ($this->lines as $line) |
|
| 131 | 131 | { |
| 132 | 132 | // we already did this |
| 133 | - if($line->isSection()) { |
|
| 133 | + if ($line->isSection()) { |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $keep = array(); |
| 152 | 152 | |
| 153 | - foreach($this->lines as $line) |
|
| 153 | + foreach ($this->lines as $line) |
|
| 154 | 154 | { |
| 155 | - if($line !== $toDelete) { |
|
| 155 | + if ($line !== $toDelete) { |
|
| 156 | 156 | $keep[] = $line; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -177,23 +177,23 @@ discard block |
||
| 177 | 177 | // Removes any superfluous values that may |
| 178 | 178 | // already exist, if there are more than the |
| 179 | 179 | // new set of values. |
| 180 | - if(is_array($value)) |
|
| 180 | + if (is_array($value)) |
|
| 181 | 181 | { |
| 182 | 182 | $values = array_values($value); |
| 183 | 183 | $amountNew = count($values); |
| 184 | 184 | $amountExisting = count($lines); |
| 185 | 185 | |
| 186 | 186 | $max = $amountNew; |
| 187 | - if($amountExisting > $max) { |
|
| 187 | + if ($amountExisting > $max) { |
|
| 188 | 188 | $max = $amountExisting; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - for($i=0; $i < $max; $i++) |
|
| 191 | + for ($i = 0; $i < $max; $i++) |
|
| 192 | 192 | { |
| 193 | 193 | // new value exists |
| 194 | - if(isset($values[$i])) |
|
| 194 | + if (isset($values[$i])) |
|
| 195 | 195 | { |
| 196 | - if(isset($lines[$i])) { |
|
| 196 | + if (isset($lines[$i])) { |
|
| 197 | 197 | $lines[$i]->setValue($values[$i]); |
| 198 | 198 | } else { |
| 199 | 199 | $this->addValueLine($name, $values[$i]); |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | else |
| 212 | 212 | { |
| 213 | 213 | // remove all superfluous lines |
| 214 | - if(!empty($lines)) |
|
| 214 | + if (!empty($lines)) |
|
| 215 | 215 | { |
| 216 | 216 | $line = array_shift($lines); // keep only the first line |
| 217 | 217 | $line->setValue($value); |
| 218 | 218 | |
| 219 | - foreach($lines as $delete) { |
|
| 219 | + foreach ($lines as $delete) { |
|
| 220 | 220 | $this->deleteLine($delete); |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
| 242 | 242 | { |
| 243 | 243 | // array value? Treat it as duplicate keys. |
| 244 | - if(is_array($value)) |
|
| 244 | + if (is_array($value)) |
|
| 245 | 245 | { |
| 246 | 246 | $values = array_values($value); |
| 247 | 247 | |
| 248 | - foreach($values as $setValue) |
|
| 248 | + foreach ($values as $setValue) |
|
| 249 | 249 | { |
| 250 | 250 | $this->addValue($name, $setValue); |
| 251 | 251 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $lines = $this->getLinesByVariable($name); |
| 257 | 257 | |
| 258 | - if(empty($lines)) |
|
| 258 | + if (empty($lines)) |
|
| 259 | 259 | { |
| 260 | 260 | $this->addValueLine($name, $value); |
| 261 | 261 | } |
@@ -263,15 +263,15 @@ discard block |
||
| 263 | 263 | { |
| 264 | 264 | $found = false; |
| 265 | 265 | |
| 266 | - foreach($lines as $line) |
|
| 266 | + foreach ($lines as $line) |
|
| 267 | 267 | { |
| 268 | - if($line->getVarValue() === $value) { |
|
| 268 | + if ($line->getVarValue() === $value) { |
|
| 269 | 269 | $found = $line; |
| 270 | 270 | break; |
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if(!$found) |
|
| 274 | + if (!$found) |
|
| 275 | 275 | { |
| 276 | 276 | $this->addValueLine($name, $value); |
| 277 | 277 | } |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | { |
| 306 | 306 | $result = array(); |
| 307 | 307 | |
| 308 | - foreach($this->lines as $line) |
|
| 308 | + foreach ($this->lines as $line) |
|
| 309 | 309 | { |
| 310 | - if($line->isValue() && $line->getVarName() === $name) { |
|
| 310 | + if ($line->isValue() && $line->getVarName() === $name) { |
|
| 311 | 311 | $result[] = $line; |
| 312 | 312 | } |
| 313 | 313 | } |
@@ -198,8 +198,7 @@ discard block |
||
| 198 | 198 | } else { |
| 199 | 199 | $this->addValueLine($name, $values[$i]); |
| 200 | 200 | } |
| 201 | - } |
|
| 202 | - else |
|
| 201 | + } else |
|
| 203 | 202 | { |
| 204 | 203 | $this->deleteLine($lines[$i]); |
| 205 | 204 | } |
@@ -219,8 +218,7 @@ discard block |
||
| 219 | 218 | foreach($lines as $delete) { |
| 220 | 219 | $this->deleteLine($delete); |
| 221 | 220 | } |
| 222 | - } |
|
| 223 | - else |
|
| 221 | + } else |
|
| 224 | 222 | { |
| 225 | 223 | $this->addValueLine($name, $value); |
| 226 | 224 | } |
@@ -258,8 +256,7 @@ discard block |
||
| 258 | 256 | if(empty($lines)) |
| 259 | 257 | { |
| 260 | 258 | $this->addValueLine($name, $value); |
| 261 | - } |
|
| 262 | - else |
|
| 259 | + } else |
|
| 263 | 260 | { |
| 264 | 261 | $found = false; |
| 265 | 262 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | protected $file; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var \ZipArchive |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var \ZipArchive |
|
| 43 | + */ |
|
| 44 | 44 | protected $zip; |
| 45 | 45 | |
| 46 | 46 | public function __construct($targetFile) |
@@ -48,33 +48,33 @@ discard block |
||
| 48 | 48 | $this->file = $targetFile; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Sets an option, among the available options: |
|
| 53 | - * |
|
| 54 | - * <ul> |
|
| 55 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
| 56 | - * </ul> |
|
| 57 | - * |
|
| 58 | - * @param string $name |
|
| 59 | - * @param mixed $value |
|
| 60 | - * @return ZIPHelper |
|
| 61 | - */ |
|
| 51 | + /** |
|
| 52 | + * Sets an option, among the available options: |
|
| 53 | + * |
|
| 54 | + * <ul> |
|
| 55 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
| 56 | + * </ul> |
|
| 57 | + * |
|
| 58 | + * @param string $name |
|
| 59 | + * @param mixed $value |
|
| 60 | + * @return ZIPHelper |
|
| 61 | + */ |
|
| 62 | 62 | public function setOption($name, $value) |
| 63 | 63 | { |
| 64 | 64 | $this->options[$name] = $value; |
| 65 | 65 | return $this; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Adds a file to the zip. By default, the file is stored |
|
| 70 | - * with the same name in the root of the zip. Use the optional |
|
| 71 | - * parameter to change the location in the zip. |
|
| 72 | - * |
|
| 73 | - * @param string $filePath |
|
| 74 | - * @param string $zipPath |
|
| 75 | - * @throws ZIPHelper_Exception |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 68 | + /** |
|
| 69 | + * Adds a file to the zip. By default, the file is stored |
|
| 70 | + * with the same name in the root of the zip. Use the optional |
|
| 71 | + * parameter to change the location in the zip. |
|
| 72 | + * |
|
| 73 | + * @param string $filePath |
|
| 74 | + * @param string $zipPath |
|
| 75 | + * @throws ZIPHelper_Exception |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | 78 | public function addFile($filePath, $zipPath=null) |
| 79 | 79 | { |
| 80 | 80 | $this->open(); |
@@ -252,13 +252,13 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | protected $exit; |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
| 257 | - * file after sending it to the browser. |
|
| 258 | - * |
|
| 259 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
| 260 | - * @see ZIPHelper::download() |
|
| 261 | - */ |
|
| 255 | + /** |
|
| 256 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
| 257 | + * file after sending it to the browser. |
|
| 258 | + * |
|
| 259 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
| 260 | + * @see ZIPHelper::download() |
|
| 261 | + */ |
|
| 262 | 262 | public function downloadAndDelete($fileName=null) |
| 263 | 263 | { |
| 264 | 264 | $this->exit = false; |
@@ -272,14 +272,14 @@ discard block |
||
| 272 | 272 | exit; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Extracts all files and folders from the zip to the |
|
| 277 | - * target folder. If no folder is specified, the files |
|
| 278 | - * are extracted into the same folder as the zip itself. |
|
| 279 | - * |
|
| 280 | - * @param string $outputFolder |
|
| 281 | - * @return boolean |
|
| 282 | - */ |
|
| 275 | + /** |
|
| 276 | + * Extracts all files and folders from the zip to the |
|
| 277 | + * target folder. If no folder is specified, the files |
|
| 278 | + * are extracted into the same folder as the zip itself. |
|
| 279 | + * |
|
| 280 | + * @param string $outputFolder |
|
| 281 | + * @return boolean |
|
| 282 | + */ |
|
| 283 | 283 | public function extractAll($outputFolder=null) |
| 284 | 284 | { |
| 285 | 285 | if(empty($outputFolder)) { |
@@ -292,9 +292,9 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * @return \ZipArchive |
|
| 297 | - */ |
|
| 295 | + /** |
|
| 296 | + * @return \ZipArchive |
|
| 297 | + */ |
|
| 298 | 298 | public function getArchive() |
| 299 | 299 | { |
| 300 | 300 | $this->open(); |
@@ -302,14 +302,14 @@ discard block |
||
| 302 | 302 | return $this->zip; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * JSON encodes the specified data and adds the json as |
|
| 307 | - * a file in the ZIP archive. |
|
| 308 | - * |
|
| 309 | - * @param mixed $data |
|
| 310 | - * @param string $zipPath |
|
| 311 | - * @return boolean |
|
| 312 | - */ |
|
| 305 | + /** |
|
| 306 | + * JSON encodes the specified data and adds the json as |
|
| 307 | + * a file in the ZIP archive. |
|
| 308 | + * |
|
| 309 | + * @param mixed $data |
|
| 310 | + * @param string $zipPath |
|
| 311 | + * @return boolean |
|
| 312 | + */ |
|
| 313 | 313 | public function addJSON($data, $zipPath) |
| 314 | 314 | { |
| 315 | 315 | return $this->addString( |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | const ERROR_OPENING_ZIP_FILE = 338003; |
| 32 | 32 | |
| 33 | - const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
| 33 | + const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
| 34 | 34 | |
| 35 | 35 | protected $options = array( |
| 36 | 36 | 'WriteThreshold' => 100 |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @throws ZIPHelper_Exception |
| 76 | 76 | * @return bool |
| 77 | 77 | */ |
| 78 | - public function addFile($filePath, $zipPath=null) |
|
| 78 | + public function addFile($filePath, $zipPath = null) |
|
| 79 | 79 | { |
| 80 | 80 | $this->open(); |
| 81 | 81 | |
@@ -120,16 +120,16 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | protected function open() |
| 122 | 122 | { |
| 123 | - if($this->open) { |
|
| 123 | + if ($this->open) { |
|
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if(!isset($this->zip)) { |
|
| 127 | + if (!isset($this->zip)) { |
|
| 128 | 128 | $this->zip = new \ZipArchive(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $flag = null; |
| 132 | - if(!file_exists($this->file)) { |
|
| 132 | + if (!file_exists($this->file)) { |
|
| 133 | 133 | $flag = \ZipArchive::CREATE; |
| 134 | 134 | } |
| 135 | 135 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $this->fileTracker++; |
| 171 | 171 | |
| 172 | - if($this->options['WriteThreshold'] < 1) { |
|
| 172 | + if ($this->options['WriteThreshold'] < 1) { |
|
| 173 | 173 | return; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | protected function close() |
| 184 | 184 | { |
| 185 | - if(!$this->open) { |
|
| 185 | + if (!$this->open) { |
|
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | throw new ZIPHelper_Exception( |
| 191 | 191 | 'Could not save ZIP file to disk', |
| 192 | 192 | sprintf( |
| 193 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
| 194 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
| 193 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
| 194 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
| 195 | 195 | 'or trying to save to a directory that does not exist.', |
| 196 | 196 | $this->file |
| 197 | 197 | ), |
@@ -228,22 +228,22 @@ discard block |
||
| 228 | 228 | * @see ZIPHelper::downloadAndDelete() |
| 229 | 229 | * @throws ZIPHelper_Exception |
| 230 | 230 | */ |
| 231 | - public function download($fileName=null) |
|
| 231 | + public function download($fileName = null) |
|
| 232 | 232 | { |
| 233 | 233 | $this->save(); |
| 234 | 234 | |
| 235 | - if(empty($fileName)) { |
|
| 235 | + if (empty($fileName)) { |
|
| 236 | 236 | $fileName = basename($this->file); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | header('Content-type: application/zip'); |
| 240 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
| 241 | - header('Content-length: ' . filesize($this->file)); |
|
| 240 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
| 241 | + header('Content-length: '.filesize($this->file)); |
|
| 242 | 242 | header('Pragma: no-cache'); |
| 243 | 243 | header('Expires: 0'); |
| 244 | 244 | readfile($this->file); |
| 245 | 245 | |
| 246 | - if($this->exit === false) { |
|
| 246 | + if ($this->exit === false) { |
|
| 247 | 247 | return; |
| 248 | 248 | } |
| 249 | 249 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param string|NULL $fileName Override the ZIP's file name for the download |
| 260 | 260 | * @see ZIPHelper::download() |
| 261 | 261 | */ |
| 262 | - public function downloadAndDelete($fileName=null) |
|
| 262 | + public function downloadAndDelete($fileName = null) |
|
| 263 | 263 | { |
| 264 | 264 | $this->exit = false; |
| 265 | 265 | |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | * @param string $outputFolder |
| 281 | 281 | * @return boolean |
| 282 | 282 | */ |
| 283 | - public function extractAll($outputFolder=null) |
|
| 283 | + public function extractAll($outputFolder = null) |
|
| 284 | 284 | { |
| 285 | - if(empty($outputFolder)) { |
|
| 285 | + if (empty($outputFolder)) { |
|
| 286 | 286 | $outputFolder = dirname($this->file); |
| 287 | 287 | } |
| 288 | 288 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * The converted string will be all lowercase. |
| 61 | 61 | * @return Transliteration |
| 62 | 62 | */ |
| 63 | - public function setLowercase(bool $lowercase=true) : Transliteration |
|
| 63 | + public function setLowercase(bool $lowercase = true) : Transliteration |
|
| 64 | 64 | { |
| 65 | 65 | $this->setOption('lowercase', true); |
| 66 | 66 | |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $result = implode('', $keep); |
| 99 | 99 | |
| 100 | - while (strstr($result, $space . $space)) { |
|
| 101 | - $result = str_replace($space . $space, $space, $result); |
|
| 100 | + while (strstr($result, $space.$space)) { |
|
| 101 | + $result = str_replace($space.$space, $space, $result); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $result = trim($result, $space); |
@@ -19,15 +19,15 @@ discard block |
||
| 19 | 19 | const TYPE_PHONE = 'phone'; |
| 20 | 20 | const TYPE_URL = 'url'; |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The original URL that was passed to the constructor. |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 22 | + /** |
|
| 23 | + * The original URL that was passed to the constructor. |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $rawURL; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $info; |
| 32 | 32 | |
| 33 | 33 | protected $isEmail = false; |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | protected $isPhone = false; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string[] |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var string[] |
|
| 43 | + */ |
|
| 44 | 44 | protected $knownSchemes = array( |
| 45 | 45 | 'ftp', |
| 46 | 46 | 'http', |
@@ -51,36 +51,36 @@ discard block |
||
| 51 | 51 | 'file' |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | 57 | protected $error; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | 62 | protected $params = array(); |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string[] |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string[] |
|
| 66 | + */ |
|
| 67 | 67 | protected $excludedParams = array(); |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var bool |
|
| 71 | - * @see URLInfo::setParamExclusion() |
|
| 72 | - */ |
|
| 69 | + /** |
|
| 70 | + * @var bool |
|
| 71 | + * @see URLInfo::setParamExclusion() |
|
| 72 | + */ |
|
| 73 | 73 | protected $paramExclusion = false; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var array |
|
| 77 | - * @see URLInfo::getTypeLabel() |
|
| 78 | - */ |
|
| 75 | + /** |
|
| 76 | + * @var array |
|
| 77 | + * @see URLInfo::getTypeLabel() |
|
| 78 | + */ |
|
| 79 | 79 | protected static $typeLabels; |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @var bool |
|
| 83 | - */ |
|
| 81 | + /** |
|
| 82 | + * @var bool |
|
| 83 | + */ |
|
| 84 | 84 | protected $highlightExcluded = false; |
| 85 | 85 | |
| 86 | 86 | protected $infoKeys = array( |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | $this->isValid = true; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Filters an URL: removes control characters and the |
|
| 182 | - * like to have a clean URL to work with. |
|
| 183 | - * |
|
| 184 | - * @param string $url |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 180 | + /** |
|
| 181 | + * Filters an URL: removes control characters and the |
|
| 182 | + * like to have a clean URL to work with. |
|
| 183 | + * |
|
| 184 | + * @param string $url |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | 187 | public static function filterURL(string $url) |
| 188 | 188 | { |
| 189 | 189 | // fix ampersands if it comes from HTML |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | return $url; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Goes through all information in the parse_url result |
|
| 211 | - * array, and attempts to fix any user errors in formatting |
|
| 212 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 213 | - */ |
|
| 209 | + /** |
|
| 210 | + * Goes through all information in the parse_url result |
|
| 211 | + * array, and attempts to fix any user errors in formatting |
|
| 212 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 213 | + */ |
|
| 214 | 214 | protected function filterParsed() |
| 215 | 215 | { |
| 216 | 216 | foreach($this->info as $key => $val) |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | return $this->isPhone; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Whether the URL is a regular URL, not one of the |
|
| 299 | - * other types like a phone number or email address. |
|
| 300 | - * |
|
| 301 | - * @return bool |
|
| 302 | - */ |
|
| 297 | + /** |
|
| 298 | + * Whether the URL is a regular URL, not one of the |
|
| 299 | + * other types like a phone number or email address. |
|
| 300 | + * |
|
| 301 | + * @return bool |
|
| 302 | + */ |
|
| 303 | 303 | public function isURL() : bool |
| 304 | 304 | { |
| 305 | 305 | $host = $this->getHost(); |
@@ -311,20 +311,20 @@ discard block |
||
| 311 | 311 | return $this->isValid; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Retrieves the host name, or an empty string if none is present. |
|
| 316 | - * |
|
| 317 | - * @return string |
|
| 318 | - */ |
|
| 314 | + /** |
|
| 315 | + * Retrieves the host name, or an empty string if none is present. |
|
| 316 | + * |
|
| 317 | + * @return string |
|
| 318 | + */ |
|
| 319 | 319 | public function getHost() : string |
| 320 | 320 | { |
| 321 | 321 | return $this->getInfoKey('host'); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Retrieves the path, or an empty string if none is present. |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 324 | + /** |
|
| 325 | + * Retrieves the path, or an empty string if none is present. |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | 328 | public function getPath() : string |
| 329 | 329 | { |
| 330 | 330 | return $this->getInfoKey('path'); |
@@ -340,10 +340,10 @@ discard block |
||
| 340 | 340 | return $this->getInfoKey('scheme'); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 345 | - * @return int |
|
| 346 | - */ |
|
| 343 | + /** |
|
| 344 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 345 | + * @return int |
|
| 346 | + */ |
|
| 347 | 347 | public function getPort() : int |
| 348 | 348 | { |
| 349 | 349 | $port = $this->getInfoKey('port'); |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | return -1; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 359 | - * |
|
| 360 | - * @return string |
|
| 361 | - * |
|
| 362 | - * @see URLInfo::getParams() |
|
| 363 | - */ |
|
| 357 | + /** |
|
| 358 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 359 | + * |
|
| 360 | + * @return string |
|
| 361 | + * |
|
| 362 | + * @see URLInfo::getParams() |
|
| 363 | + */ |
|
| 364 | 364 | public function getQuery() : string |
| 365 | 365 | { |
| 366 | 366 | return $this->getInfoKey('query'); |
@@ -376,20 +376,20 @@ discard block |
||
| 376 | 376 | return $this->getInfoKey('pass'); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Whether the URL contains a port number. |
|
| 381 | - * @return bool |
|
| 382 | - */ |
|
| 379 | + /** |
|
| 380 | + * Whether the URL contains a port number. |
|
| 381 | + * @return bool |
|
| 382 | + */ |
|
| 383 | 383 | public function hasPort() : bool |
| 384 | 384 | { |
| 385 | 385 | return $this->getPort() !== -1; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * Alias for the hasParams() method. |
|
| 390 | - * @return bool |
|
| 391 | - * @see URLInfo::hasParams() |
|
| 392 | - */ |
|
| 388 | + /** |
|
| 389 | + * Alias for the hasParams() method. |
|
| 390 | + * @return bool |
|
| 391 | + * @see URLInfo::hasParams() |
|
| 392 | + */ |
|
| 393 | 393 | public function hasQuery() : bool |
| 394 | 394 | { |
| 395 | 395 | return $this->hasParams(); |
@@ -470,25 +470,25 @@ discard block |
||
| 470 | 470 | return $normalized; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 475 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 476 | - * the same links with a different parameter order will have the |
|
| 477 | - * same hash. |
|
| 478 | - * |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 473 | + /** |
|
| 474 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 475 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 476 | + * the same links with a different parameter order will have the |
|
| 477 | + * same hash. |
|
| 478 | + * |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | 481 | public function getHash() |
| 482 | 482 | { |
| 483 | 483 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - /** |
|
| 487 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 488 | - * class names. |
|
| 489 | - * |
|
| 490 | - * @return string Will return an empty string if the URL is not valid. |
|
| 491 | - */ |
|
| 486 | + /** |
|
| 487 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 488 | + * class names. |
|
| 489 | + * |
|
| 490 | + * @return string Will return an empty string if the URL is not valid. |
|
| 491 | + */ |
|
| 492 | 492 | public function getHighlighted() : string |
| 493 | 493 | { |
| 494 | 494 | if(!$this->isValid) { |
@@ -670,15 +670,15 @@ discard block |
||
| 670 | 670 | return count($params); |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - /** |
|
| 674 | - * Retrieves all parameters specified in the url, |
|
| 675 | - * if any, as an associative array. |
|
| 676 | - * |
|
| 677 | - * NOTE: Ignores parameters that have been added |
|
| 678 | - * to the excluded parameters list. |
|
| 679 | - * |
|
| 680 | - * @return array |
|
| 681 | - */ |
|
| 673 | + /** |
|
| 674 | + * Retrieves all parameters specified in the url, |
|
| 675 | + * if any, as an associative array. |
|
| 676 | + * |
|
| 677 | + * NOTE: Ignores parameters that have been added |
|
| 678 | + * to the excluded parameters list. |
|
| 679 | + * |
|
| 680 | + * @return array |
|
| 681 | + */ |
|
| 682 | 682 | public function getParams() : array |
| 683 | 683 | { |
| 684 | 684 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -695,26 +695,26 @@ discard block |
||
| 695 | 695 | return $keep; |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - /** |
|
| 699 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 700 | - * @return string[] |
|
| 701 | - */ |
|
| 698 | + /** |
|
| 699 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 700 | + * @return string[] |
|
| 701 | + */ |
|
| 702 | 702 | public function getParamNames() : array |
| 703 | 703 | { |
| 704 | 704 | $params = $this->getParams(); |
| 705 | 705 | return array_keys($params); |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | - /** |
|
| 709 | - * Excludes an URL parameter entirely if present: |
|
| 710 | - * the parser will act as if the parameter was not |
|
| 711 | - * even present in the source URL, effectively |
|
| 712 | - * stripping it. |
|
| 713 | - * |
|
| 714 | - * @param string $name |
|
| 715 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 716 | - * @return URLInfo |
|
| 717 | - */ |
|
| 708 | + /** |
|
| 709 | + * Excludes an URL parameter entirely if present: |
|
| 710 | + * the parser will act as if the parameter was not |
|
| 711 | + * even present in the source URL, effectively |
|
| 712 | + * stripping it. |
|
| 713 | + * |
|
| 714 | + * @param string $name |
|
| 715 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 716 | + * @return URLInfo |
|
| 717 | + */ |
|
| 718 | 718 | public function excludeParam(string $name, string $reason) : URLInfo |
| 719 | 719 | { |
| 720 | 720 | if(!isset($this->excludedParams[$name])) |
@@ -779,25 +779,25 @@ discard block |
||
| 779 | 779 | return self::$typeLabels[$this->getType()]; |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * Whether excluded parameters should be highlighted in |
|
| 784 | - * a different color in the URL when using the |
|
| 785 | - * {@link URLInfo::getHighlighted()} method. |
|
| 786 | - * |
|
| 787 | - * @param bool $highlight |
|
| 788 | - * @return URLInfo |
|
| 789 | - */ |
|
| 782 | + /** |
|
| 783 | + * Whether excluded parameters should be highlighted in |
|
| 784 | + * a different color in the URL when using the |
|
| 785 | + * {@link URLInfo::getHighlighted()} method. |
|
| 786 | + * |
|
| 787 | + * @param bool $highlight |
|
| 788 | + * @return URLInfo |
|
| 789 | + */ |
|
| 790 | 790 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 791 | 791 | { |
| 792 | 792 | $this->highlightExcluded = $highlight; |
| 793 | 793 | return $this; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - /** |
|
| 797 | - * Returns an array with all relevant URL information. |
|
| 798 | - * |
|
| 799 | - * @return array |
|
| 800 | - */ |
|
| 796 | + /** |
|
| 797 | + * Returns an array with all relevant URL information. |
|
| 798 | + * |
|
| 799 | + * @return array |
|
| 800 | + */ |
|
| 801 | 801 | public function toArray() : array |
| 802 | 802 | { |
| 803 | 803 | return array( |
@@ -841,24 +841,24 @@ discard block |
||
| 841 | 841 | return $this; |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - /** |
|
| 845 | - * Whether the parameter exclusion mode is enabled: |
|
| 846 | - * In this case, if any parameters have been added to the |
|
| 847 | - * exclusion list, all relevant methods will exclude these. |
|
| 848 | - * |
|
| 849 | - * @return bool |
|
| 850 | - */ |
|
| 844 | + /** |
|
| 845 | + * Whether the parameter exclusion mode is enabled: |
|
| 846 | + * In this case, if any parameters have been added to the |
|
| 847 | + * exclusion list, all relevant methods will exclude these. |
|
| 848 | + * |
|
| 849 | + * @return bool |
|
| 850 | + */ |
|
| 851 | 851 | public function isParamExclusionEnabled() : bool |
| 852 | 852 | { |
| 853 | 853 | return $this->paramExclusion; |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - /** |
|
| 857 | - * Checks whether the link contains any parameters that |
|
| 858 | - * are on the list of excluded parameters. |
|
| 859 | - * |
|
| 860 | - * @return bool |
|
| 861 | - */ |
|
| 856 | + /** |
|
| 857 | + * Checks whether the link contains any parameters that |
|
| 858 | + * are on the list of excluded parameters. |
|
| 859 | + * |
|
| 860 | + * @return bool |
|
| 861 | + */ |
|
| 862 | 862 | public function containsExcludedParams() : bool |
| 863 | 863 | { |
| 864 | 864 | if(empty($this->excludedParams)) { |
@@ -117,26 +117,26 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | $this->filterParsed(); |
| 119 | 119 | |
| 120 | - if($this->detectEmail()) { |
|
| 120 | + if ($this->detectEmail()) { |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if($this->detectFragmentLink()) { |
|
| 124 | + if ($this->detectFragmentLink()) { |
|
| 125 | 125 | return; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if($this->detectPhoneLink()) { |
|
| 128 | + if ($this->detectPhoneLink()) { |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if(!$this->isValid) { |
|
| 132 | + if (!$this->isValid) { |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // no scheme found: it may be an email address without the mailto: |
| 137 | 137 | // It can't be a variable, since without the scheme it would already |
| 138 | 138 | // have been recognized as a vaiable only link. |
| 139 | - if(!isset($this->info['scheme'])) { |
|
| 139 | + if (!isset($this->info['scheme'])) { |
|
| 140 | 140 | $this->setError( |
| 141 | 141 | self::ERROR_MISSING_SCHEME, |
| 142 | 142 | t('Cannot determine the link\'s scheme, e.g. %1$s.', 'http') |
@@ -145,10 +145,10 @@ discard block |
||
| 145 | 145 | return; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if(!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 148 | + if (!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 149 | 149 | $this->setError( |
| 150 | 150 | self::ERROR_INVALID_SCHEME, |
| 151 | - t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' . |
|
| 151 | + t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '. |
|
| 152 | 152 | t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes)) |
| 153 | 153 | ); |
| 154 | 154 | $this->isValid = false; |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | // every link needs a host. This case can happen for ex, if |
| 159 | 159 | // the link starts with a typo with only one slash, like: |
| 160 | 160 | // "http:/hostname" |
| 161 | - if(!isset($this->info['host'])) { |
|
| 161 | + if (!isset($this->info['host'])) { |
|
| 162 | 162 | $this->setError( |
| 163 | 163 | self::ERROR_MISSING_HOST, |
| 164 | - t('Cannot determine the link\'s host name.') . ' ' . |
|
| 164 | + t('Cannot determine the link\'s host name.').' '. |
|
| 165 | 165 | t('This usually happens when there\'s a typo somewhere.') |
| 166 | 166 | ); |
| 167 | 167 | $this->isValid = false; |
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if(!empty($this->info['query'])) |
|
| 171 | + if (!empty($this->info['query'])) |
|
| 172 | 172 | { |
| 173 | 173 | $this->params = \AppUtils\ConvertHelper::parseQueryString($this->info['query']); |
| 174 | 174 | ksort($this->params); |
@@ -213,30 +213,30 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | protected function filterParsed() |
| 215 | 215 | { |
| 216 | - foreach($this->info as $key => $val) |
|
| 216 | + foreach ($this->info as $key => $val) |
|
| 217 | 217 | { |
| 218 | - if(is_string($val)) { |
|
| 218 | + if (is_string($val)) { |
|
| 219 | 219 | $this->info[$key] = trim($val); |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if(isset($this->info['host'])) { |
|
| 223 | + if (isset($this->info['host'])) { |
|
| 224 | 224 | $this->info['host'] = str_replace(' ', '', $this->info['host']); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if(isset($this->info['path'])) { |
|
| 227 | + if (isset($this->info['path'])) { |
|
| 228 | 228 | $this->info['path'] = str_replace(' ', '', $this->info['path']); |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | protected function detectEmail() |
| 233 | 233 | { |
| 234 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 234 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 235 | 235 | $this->isEmail = true; |
| 236 | 236 | return true; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if(isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 239 | + if (isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 240 | 240 | { |
| 241 | 241 | $this->info['scheme'] = 'email'; |
| 242 | 242 | $this->isEmail = true; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | protected function detectFragmentLink() |
| 250 | 250 | { |
| 251 | - if(isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 251 | + if (isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 252 | 252 | $this->isFragment = true; |
| 253 | 253 | return true; |
| 254 | 254 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | protected function detectPhoneLink() |
| 260 | 260 | { |
| 261 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 261 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 262 | 262 | $this->isPhone = true; |
| 263 | 263 | return true; |
| 264 | 264 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function isSecure() |
| 274 | 274 | { |
| 275 | - if(isset($this->info['scheme']) && $this->info['scheme']=='https') { |
|
| 275 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'https') { |
|
| 276 | 276 | return true; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | public function getPort() : int |
| 348 | 348 | { |
| 349 | 349 | $port = $this->getInfoKey('port'); |
| 350 | - if(!empty($port)) { |
|
| 350 | + if (!empty($port)) { |
|
| 351 | 351 | return (int)$port; |
| 352 | 352 | } |
| 353 | 353 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | |
| 428 | 428 | protected function getInfoKey(string $name) : string |
| 429 | 429 | { |
| 430 | - if(isset($this->info[$name])) { |
|
| 430 | + if (isset($this->info[$name])) { |
|
| 431 | 431 | return (string)$this->info[$name]; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -436,34 +436,34 @@ discard block |
||
| 436 | 436 | |
| 437 | 437 | public function getNormalized() : string |
| 438 | 438 | { |
| 439 | - if(!$this->isValid) { |
|
| 439 | + if (!$this->isValid) { |
|
| 440 | 440 | return ''; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - if($this->isFragment === true) |
|
| 443 | + if ($this->isFragment === true) |
|
| 444 | 444 | { |
| 445 | 445 | return '#'.$this->getFragment(); |
| 446 | 446 | } |
| 447 | - else if($this->isPhone === true) |
|
| 447 | + else if ($this->isPhone === true) |
|
| 448 | 448 | { |
| 449 | 449 | return 'tel://'.$this->getHost(); |
| 450 | 450 | } |
| 451 | - else if($this->isEmail === true) |
|
| 451 | + else if ($this->isEmail === true) |
|
| 452 | 452 | { |
| 453 | 453 | return 'mailto:'.$this->getPath(); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | $normalized = $this->info['scheme'].'://'.$this->info['host']; |
| 457 | - if(isset($this->info['path'])) { |
|
| 457 | + if (isset($this->info['path'])) { |
|
| 458 | 458 | $normalized .= $this->info['path']; |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | $params = $this->getParams(); |
| 462 | - if(!empty($params)) { |
|
| 462 | + if (!empty($params)) { |
|
| 463 | 463 | $normalized .= '?'.http_build_query($params); |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - if(isset($this->info['fragment'])) { |
|
| 466 | + if (isset($this->info['fragment'])) { |
|
| 467 | 467 | $normalized .= '#'.$this->info['fragment']; |
| 468 | 468 | } |
| 469 | 469 | |
@@ -491,11 +491,11 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | public function getHighlighted() : string |
| 493 | 493 | { |
| 494 | - if(!$this->isValid) { |
|
| 494 | + if (!$this->isValid) { |
|
| 495 | 495 | return ''; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - if($this->isEmail) { |
|
| 498 | + if ($this->isEmail) { |
|
| 499 | 499 | return sprintf( |
| 500 | 500 | '<span class="link-scheme scheme-mailto">mailto:</span>'. |
| 501 | 501 | '<span class="link-host">%s</span>', |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | ); |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - if($this->isFragment) { |
|
| 506 | + if ($this->isFragment) { |
|
| 507 | 507 | return sprintf( |
| 508 | 508 | '<span class="link-fragment-sign">#</span>'. |
| 509 | 509 | '<span class="link-fragment-value">%s</span>', |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | ); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if($this->hasScheme()) |
|
| 514 | + if ($this->hasScheme()) |
|
| 515 | 515 | { |
| 516 | 516 | $result = sprintf( |
| 517 | 517 | '<span class="link-scheme scheme-%1$s">'. |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | $result .= '<span class="link-component double-slashes">//</span>'; |
| 525 | 525 | |
| 526 | - if($this->hasUsername()) |
|
| 526 | + if ($this->hasUsername()) |
|
| 527 | 527 | { |
| 528 | 528 | $result .= sprintf( |
| 529 | 529 | '<span class="link-credentials">%s</span>'. |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | ); |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - if($this->hasHost()) |
|
| 538 | + if ($this->hasHost()) |
|
| 539 | 539 | { |
| 540 | 540 | $result .= |
| 541 | 541 | sprintf( |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | ); |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - if($this->hasPort()) |
|
| 547 | + if ($this->hasPort()) |
|
| 548 | 548 | { |
| 549 | 549 | $result .= sprintf( |
| 550 | 550 | '<span class="link-component port-separator">:</span>'. |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | ); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - if($this->hasPath()) |
|
| 556 | + if ($this->hasPath()) |
|
| 557 | 557 | { |
| 558 | 558 | $path = str_replace(array(';', '='), array(';<wbr>', '=<wbr>'), $this->getPath()); |
| 559 | 559 | $tokens = explode('/', $path); |
@@ -564,11 +564,11 @@ discard block |
||
| 564 | 564 | ); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - if(!empty($this->params)) |
|
| 567 | + if (!empty($this->params)) |
|
| 568 | 568 | { |
| 569 | 569 | $tokens = array(); |
| 570 | 570 | |
| 571 | - foreach($this->params as $param => $value) |
|
| 571 | + foreach ($this->params as $param => $value) |
|
| 572 | 572 | { |
| 573 | 573 | $parts = sprintf( |
| 574 | 574 | '<span class="link-param-name">%s</span>'. |
@@ -586,10 +586,10 @@ discard block |
||
| 586 | 586 | $tag = ''; |
| 587 | 587 | |
| 588 | 588 | // is parameter exclusion enabled, and is this an excluded parameter? |
| 589 | - if($this->paramExclusion && isset($this->excludedParams[$param])) |
|
| 589 | + if ($this->paramExclusion && isset($this->excludedParams[$param])) |
|
| 590 | 590 | { |
| 591 | 591 | // display the excluded parameter, but highlight it |
| 592 | - if($this->highlightExcluded) |
|
| 592 | + if ($this->highlightExcluded) |
|
| 593 | 593 | { |
| 594 | 594 | $tooltip = $this->excludedParams[$param]; |
| 595 | 595 | |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | '<span class="link-component query-sign">?</span>'.implode('<span class="link-component param-separator">&</span>', $tokens); |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | - if(isset($this->info['fragment'])) { |
|
| 622 | + if (isset($this->info['fragment'])) { |
|
| 623 | 623 | $result .= sprintf( |
| 624 | 624 | '<span class="link-fragment-sign">#</span>'. |
| 625 | 625 | '<span class="link-fragment">%s</span>', |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | public function getErrorMessage() : string |
| 644 | 644 | { |
| 645 | - if(isset($this->error)) { |
|
| 645 | + if (isset($this->error)) { |
|
| 646 | 646 | return $this->error['message']; |
| 647 | 647 | } |
| 648 | 648 | |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | |
| 652 | 652 | public function getErrorCode() : int |
| 653 | 653 | { |
| 654 | - if(isset($this->error)) { |
|
| 654 | + if (isset($this->error)) { |
|
| 655 | 655 | return $this->error['code']; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -681,13 +681,13 @@ discard block |
||
| 681 | 681 | */ |
| 682 | 682 | public function getParams() : array |
| 683 | 683 | { |
| 684 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 684 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 685 | 685 | return $this->params; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | $keep = array(); |
| 689 | - foreach($this->params as $name => $value) { |
|
| 690 | - if(!isset($this->excludedParams[$name])) { |
|
| 689 | + foreach ($this->params as $name => $value) { |
|
| 690 | + if (!isset($this->excludedParams[$name])) { |
|
| 691 | 691 | $keep[$name] = $value; |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | */ |
| 718 | 718 | public function excludeParam(string $name, string $reason) : URLInfo |
| 719 | 719 | { |
| 720 | - if(!isset($this->excludedParams[$name])) |
|
| 720 | + if (!isset($this->excludedParams[$name])) |
|
| 721 | 721 | { |
| 722 | 722 | $this->excludedParams[$name] = $reason; |
| 723 | 723 | $this->setParamExclusion(); |
@@ -738,15 +738,15 @@ discard block |
||
| 738 | 738 | */ |
| 739 | 739 | public function getType() : string |
| 740 | 740 | { |
| 741 | - if($this->isEmail) { |
|
| 741 | + if ($this->isEmail) { |
|
| 742 | 742 | return self::TYPE_EMAIL; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - if($this->isFragment) { |
|
| 745 | + if ($this->isFragment) { |
|
| 746 | 746 | return self::TYPE_FRAGMENT; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - if($this->isPhone) { |
|
| 749 | + if ($this->isPhone) { |
|
| 750 | 750 | return self::TYPE_PHONE; |
| 751 | 751 | } |
| 752 | 752 | |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | |
| 756 | 756 | public function getTypeLabel() : string |
| 757 | 757 | { |
| 758 | - if(!isset(self::$typeLabels)) |
|
| 758 | + if (!isset(self::$typeLabels)) |
|
| 759 | 759 | { |
| 760 | 760 | self::$typeLabels = array( |
| 761 | 761 | self::TYPE_EMAIL => t('Email'), |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | |
| 768 | 768 | $type = $this->getType(); |
| 769 | 769 | |
| 770 | - if(!isset(self::$typeLabels[$type])) |
|
| 770 | + if (!isset(self::$typeLabels[$type])) |
|
| 771 | 771 | { |
| 772 | 772 | throw new BaseException( |
| 773 | 773 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * @param bool $highlight |
| 788 | 788 | * @return URLInfo |
| 789 | 789 | */ |
| 790 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
| 790 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
| 791 | 791 | { |
| 792 | 792 | $this->highlightExcluded = $highlight; |
| 793 | 793 | return $this; |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * @see URLInfo::isParamExclusionEnabled() |
| 836 | 836 | * @see URLInfo::setHighlightExcluded() |
| 837 | 837 | */ |
| 838 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
| 838 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
| 839 | 839 | { |
| 840 | 840 | $this->paramExclusion = $enabled; |
| 841 | 841 | return $this; |
@@ -861,13 +861,13 @@ discard block |
||
| 861 | 861 | */ |
| 862 | 862 | public function containsExcludedParams() : bool |
| 863 | 863 | { |
| 864 | - if(empty($this->excludedParams)) { |
|
| 864 | + if (empty($this->excludedParams)) { |
|
| 865 | 865 | return false; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | $names = array_keys($this->params); |
| 869 | - foreach($names as $name) { |
|
| 870 | - if(isset($this->excludedParams[$name])) { |
|
| 869 | + foreach ($names as $name) { |
|
| 870 | + if (isset($this->excludedParams[$name])) { |
|
| 871 | 871 | return true; |
| 872 | 872 | } |
| 873 | 873 | } |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | |
| 884 | 884 | public function offsetSet($offset, $value) |
| 885 | 885 | { |
| 886 | - if(in_array($offset, $this->infoKeys)) { |
|
| 886 | + if (in_array($offset, $this->infoKeys)) { |
|
| 887 | 887 | $this->info[$offset] = $value; |
| 888 | 888 | } |
| 889 | 889 | } |
@@ -900,11 +900,11 @@ discard block |
||
| 900 | 900 | |
| 901 | 901 | public function offsetGet($offset) |
| 902 | 902 | { |
| 903 | - if($offset === 'port') { |
|
| 903 | + if ($offset === 'port') { |
|
| 904 | 904 | return $this->getPort(); |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - if(in_array($offset, $this->infoKeys)) { |
|
| 907 | + if (in_array($offset, $this->infoKeys)) { |
|
| 908 | 908 | return $this->getInfoKey($offset); |
| 909 | 909 | } |
| 910 | 910 | |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | { |
| 916 | 916 | $cssFolder = realpath(__DIR__.'/../css'); |
| 917 | 917 | |
| 918 | - if($cssFolder === false) { |
|
| 918 | + if ($cssFolder === false) { |
|
| 919 | 919 | throw new BaseException( |
| 920 | 920 | 'Cannot find package CSS folder.', |
| 921 | 921 | null, |
@@ -443,12 +443,10 @@ discard block |
||
| 443 | 443 | if($this->isFragment === true) |
| 444 | 444 | { |
| 445 | 445 | return '#'.$this->getFragment(); |
| 446 | - } |
|
| 447 | - else if($this->isPhone === true) |
|
| 446 | + } else if($this->isPhone === true) |
|
| 448 | 447 | { |
| 449 | 448 | return 'tel://'.$this->getHost(); |
| 450 | - } |
|
| 451 | - else if($this->isEmail === true) |
|
| 449 | + } else if($this->isEmail === true) |
|
| 452 | 450 | { |
| 453 | 451 | return 'mailto:'.$this->getPath(); |
| 454 | 452 | } |
@@ -598,13 +596,11 @@ discard block |
||
| 598 | 596 | $tooltip, |
| 599 | 597 | $parts |
| 600 | 598 | ); |
| 601 | - } |
|
| 602 | - else |
|
| 599 | + } else |
|
| 603 | 600 | { |
| 604 | 601 | continue; |
| 605 | 602 | } |
| 606 | - } |
|
| 607 | - else |
|
| 603 | + } else |
|
| 608 | 604 | { |
| 609 | 605 | $tag = sprintf( |
| 610 | 606 | '<span class="link-param">%s</span>', |
@@ -1278,12 +1278,14 @@ discard block |
||
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | $total = ($total * 60) + ($interval->i ); |
| 1281 | - if ($unit == self::INTERVAL_MINUTES) |
|
| 1282 | - return $total; |
|
| 1281 | + if ($unit == self::INTERVAL_MINUTES) { |
|
| 1282 | + return $total; |
|
| 1283 | + } |
|
| 1283 | 1284 | |
| 1284 | 1285 | $total = ($total * 60) + ($interval->s ); |
| 1285 | - if ($unit == self::INTERVAL_SECONDS) |
|
| 1286 | - return $total; |
|
| 1286 | + if ($unit == self::INTERVAL_SECONDS) { |
|
| 1287 | + return $total; |
|
| 1288 | + } |
|
| 1287 | 1289 | |
| 1288 | 1290 | return 0; |
| 1289 | 1291 | } |
@@ -1461,8 +1463,7 @@ discard block |
||
| 1461 | 1463 | if (mb_strlen($actual.$word) <= $width) |
| 1462 | 1464 | { |
| 1463 | 1465 | $actual .= $word.' '; |
| 1464 | - } |
|
| 1465 | - else |
|
| 1466 | + } else |
|
| 1466 | 1467 | { |
| 1467 | 1468 | if ($actual != '') { |
| 1468 | 1469 | $line .= rtrim($actual).$break; |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | return $bytes . ' ' . t('B'); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - /** |
|
| 439 | - * Cuts a text to the specified length if it is longer than the |
|
| 440 | - * target length. Appends a text to signify it has been cut at |
|
| 441 | - * the end of the string. |
|
| 442 | - * |
|
| 443 | - * @param string $text |
|
| 444 | - * @param int $targetLength |
|
| 445 | - * @param string $append |
|
| 446 | - * @return string |
|
| 447 | - */ |
|
| 438 | + /** |
|
| 439 | + * Cuts a text to the specified length if it is longer than the |
|
| 440 | + * target length. Appends a text to signify it has been cut at |
|
| 441 | + * the end of the string. |
|
| 442 | + * |
|
| 443 | + * @param string $text |
|
| 444 | + * @param int $targetLength |
|
| 445 | + * @param string $append |
|
| 446 | + * @return string |
|
| 447 | + */ |
|
| 448 | 448 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 449 | 449 | { |
| 450 | 450 | $length = mb_strlen($text); |
@@ -514,27 +514,27 @@ discard block |
||
| 514 | 514 | return self::$booleanStrings[$string]; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Whether the specified string is a boolean string or boolean value. |
|
| 519 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | - * |
|
| 521 | - * @param mixed $string |
|
| 522 | - * @return bool |
|
| 523 | - * @deprecated |
|
| 524 | - * @see ConvertHelper::isBoolean() |
|
| 525 | - */ |
|
| 517 | + /** |
|
| 518 | + * Whether the specified string is a boolean string or boolean value. |
|
| 519 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | + * |
|
| 521 | + * @param mixed $string |
|
| 522 | + * @return bool |
|
| 523 | + * @deprecated |
|
| 524 | + * @see ConvertHelper::isBoolean() |
|
| 525 | + */ |
|
| 526 | 526 | public static function isBooleanString($string) : bool |
| 527 | 527 | { |
| 528 | 528 | return self::isBoolean($string); |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - /** |
|
| 532 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | - * |
|
| 534 | - * @param string $text |
|
| 535 | - * @return string |
|
| 536 | - * @deprecated |
|
| 537 | - */ |
|
| 531 | + /** |
|
| 532 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | + * |
|
| 534 | + * @param string $text |
|
| 535 | + * @return string |
|
| 536 | + * @deprecated |
|
| 537 | + */ |
|
| 538 | 538 | public static function text_makeXMLCompliant($text) |
| 539 | 539 | { |
| 540 | 540 | return XMLHelper::string2xml($text); |
@@ -636,13 +636,13 @@ discard block |
||
| 636 | 636 | return $translit->convert($string); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Retrieves the HEX character codes for all control |
|
| 641 | - * characters that the {@link stripControlCharacters()} |
|
| 642 | - * method will remove. |
|
| 643 | - * |
|
| 644 | - * @return string[] |
|
| 645 | - */ |
|
| 639 | + /** |
|
| 640 | + * Retrieves the HEX character codes for all control |
|
| 641 | + * characters that the {@link stripControlCharacters()} |
|
| 642 | + * method will remove. |
|
| 643 | + * |
|
| 644 | + * @return string[] |
|
| 645 | + */ |
|
| 646 | 646 | public static function getControlCharactersAsHex() |
| 647 | 647 | { |
| 648 | 648 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -678,13 +678,13 @@ discard block |
||
| 678 | 678 | return $stack; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - /** |
|
| 682 | - * Retrieves an array of all control characters that |
|
| 683 | - * the {@link stripControlCharacters()} method will |
|
| 684 | - * remove, as the actual UTF-8 characters. |
|
| 685 | - * |
|
| 686 | - * @return string[] |
|
| 687 | - */ |
|
| 681 | + /** |
|
| 682 | + * Retrieves an array of all control characters that |
|
| 683 | + * the {@link stripControlCharacters()} method will |
|
| 684 | + * remove, as the actual UTF-8 characters. |
|
| 685 | + * |
|
| 686 | + * @return string[] |
|
| 687 | + */ |
|
| 688 | 688 | public static function getControlCharactersAsUTF8() |
| 689 | 689 | { |
| 690 | 690 | $chars = self::getControlCharactersAsHex(); |
@@ -697,12 +697,12 @@ discard block |
||
| 697 | 697 | return $result; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - /** |
|
| 701 | - * Retrieves all control characters as JSON encoded |
|
| 702 | - * characters, e.g. "\u200b". |
|
| 703 | - * |
|
| 704 | - * @return string[] |
|
| 705 | - */ |
|
| 700 | + /** |
|
| 701 | + * Retrieves all control characters as JSON encoded |
|
| 702 | + * characters, e.g. "\u200b". |
|
| 703 | + * |
|
| 704 | + * @return string[] |
|
| 705 | + */ |
|
| 706 | 706 | public static function getControlCharactersAsJSON() |
| 707 | 707 | { |
| 708 | 708 | $chars = self::getControlCharactersAsHex(); |
@@ -759,20 +759,20 @@ discard block |
||
| 759 | 759 | return preg_replace(self::$controlCharsRegex, '', $string); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - /** |
|
| 763 | - * Converts a unicode character to the PHPO notation. |
|
| 764 | - * |
|
| 765 | - * Example: |
|
| 766 | - * |
|
| 767 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | - * |
|
| 769 | - * Returns |
|
| 770 | - * |
|
| 771 | - * <pre>\x0</pre> |
|
| 772 | - * |
|
| 773 | - * @param string $unicodeChar |
|
| 774 | - * @return string |
|
| 775 | - */ |
|
| 762 | + /** |
|
| 763 | + * Converts a unicode character to the PHPO notation. |
|
| 764 | + * |
|
| 765 | + * Example: |
|
| 766 | + * |
|
| 767 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | + * |
|
| 769 | + * Returns |
|
| 770 | + * |
|
| 771 | + * <pre>\x0</pre> |
|
| 772 | + * |
|
| 773 | + * @param string $unicodeChar |
|
| 774 | + * @return string |
|
| 775 | + */ |
|
| 776 | 776 | public static function unicodeChar2php($unicodeChar) |
| 777 | 777 | { |
| 778 | 778 | $unicodeChar = json_decode($unicodeChar); |
@@ -895,25 +895,25 @@ discard block |
||
| 895 | 895 | return 'false'; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - /** |
|
| 899 | - * Converts an associative array with attribute name > value pairs |
|
| 900 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | - * attribute values are ignored. |
|
| 902 | - * |
|
| 903 | - * Example: |
|
| 904 | - * |
|
| 905 | - * array2attributeString(array( |
|
| 906 | - * 'id' => 45, |
|
| 907 | - * 'href' => 'http://www.mistralys.com' |
|
| 908 | - * )); |
|
| 909 | - * |
|
| 910 | - * Result: |
|
| 911 | - * |
|
| 912 | - * id="45" href="http://www.mistralys.com" |
|
| 913 | - * |
|
| 914 | - * @param array $array |
|
| 915 | - * @return string |
|
| 916 | - */ |
|
| 898 | + /** |
|
| 899 | + * Converts an associative array with attribute name > value pairs |
|
| 900 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | + * attribute values are ignored. |
|
| 902 | + * |
|
| 903 | + * Example: |
|
| 904 | + * |
|
| 905 | + * array2attributeString(array( |
|
| 906 | + * 'id' => 45, |
|
| 907 | + * 'href' => 'http://www.mistralys.com' |
|
| 908 | + * )); |
|
| 909 | + * |
|
| 910 | + * Result: |
|
| 911 | + * |
|
| 912 | + * id="45" href="http://www.mistralys.com" |
|
| 913 | + * |
|
| 914 | + * @param array $array |
|
| 915 | + * @return string |
|
| 916 | + */ |
|
| 917 | 917 | public static function array2attributeString($array) |
| 918 | 918 | { |
| 919 | 919 | $tokens = array(); |
@@ -932,14 +932,14 @@ discard block |
||
| 932 | 932 | return ' '.implode(' ', $tokens); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - /** |
|
| 936 | - * Converts a string so it can safely be used in a javascript |
|
| 937 | - * statement in an HTML tag: uses single quotes around the string |
|
| 938 | - * and encodes all special characters as needed. |
|
| 939 | - * |
|
| 940 | - * @param string $string |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 935 | + /** |
|
| 936 | + * Converts a string so it can safely be used in a javascript |
|
| 937 | + * statement in an HTML tag: uses single quotes around the string |
|
| 938 | + * and encodes all special characters as needed. |
|
| 939 | + * |
|
| 940 | + * @param string $string |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | 943 | public static function string2attributeJS($string, $quoted=true) |
| 944 | 944 | { |
| 945 | 945 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -950,15 +950,15 @@ discard block |
||
| 950 | 950 | return $converted; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - /** |
|
| 954 | - * Checks if the specified string is a boolean value, which |
|
| 955 | - * includes string representations of boolean values, like |
|
| 956 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | - * or <code>false</code>. |
|
| 958 | - * |
|
| 959 | - * @param mixed $value |
|
| 960 | - * @return boolean |
|
| 961 | - */ |
|
| 953 | + /** |
|
| 954 | + * Checks if the specified string is a boolean value, which |
|
| 955 | + * includes string representations of boolean values, like |
|
| 956 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | + * or <code>false</code>. |
|
| 958 | + * |
|
| 959 | + * @param mixed $value |
|
| 960 | + * @return boolean |
|
| 961 | + */ |
|
| 962 | 962 | public static function isBoolean($value) : bool |
| 963 | 963 | { |
| 964 | 964 | if(is_bool($value)) { |
@@ -972,12 +972,12 @@ discard block |
||
| 972 | 972 | return array_key_exists($value, self::$booleanStrings); |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - /** |
|
| 976 | - * Converts an associative array to an HTML style attribute value string. |
|
| 977 | - * |
|
| 978 | - * @param array $subject |
|
| 979 | - * @return string |
|
| 980 | - */ |
|
| 975 | + /** |
|
| 976 | + * Converts an associative array to an HTML style attribute value string. |
|
| 977 | + * |
|
| 978 | + * @param array $subject |
|
| 979 | + * @return string |
|
| 980 | + */ |
|
| 981 | 981 | public static function array2styleString(array $subject) : string |
| 982 | 982 | { |
| 983 | 983 | $tokens = array(); |
@@ -988,23 +988,23 @@ discard block |
||
| 988 | 988 | return implode(';', $tokens); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - /** |
|
| 992 | - * Converts a DateTime object to a timestamp, which |
|
| 993 | - * is PHP 5.2 compatible. |
|
| 994 | - * |
|
| 995 | - * @param \DateTime $date |
|
| 996 | - * @return integer |
|
| 997 | - */ |
|
| 991 | + /** |
|
| 992 | + * Converts a DateTime object to a timestamp, which |
|
| 993 | + * is PHP 5.2 compatible. |
|
| 994 | + * |
|
| 995 | + * @param \DateTime $date |
|
| 996 | + * @return integer |
|
| 997 | + */ |
|
| 998 | 998 | public static function date2timestamp(\DateTime $date) : int |
| 999 | 999 | { |
| 1000 | 1000 | return (int)$date->format('U'); |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - /** |
|
| 1004 | - * Converts a timestamp into a DateTime instance. |
|
| 1005 | - * @param int $timestamp |
|
| 1006 | - * @return \DateTime |
|
| 1007 | - */ |
|
| 1003 | + /** |
|
| 1004 | + * Converts a timestamp into a DateTime instance. |
|
| 1005 | + * @param int $timestamp |
|
| 1006 | + * @return \DateTime |
|
| 1007 | + */ |
|
| 1008 | 1008 | public static function timestamp2date(int $timestamp) : \DateTime |
| 1009 | 1009 | { |
| 1010 | 1010 | $date = new \DateTime(); |
@@ -1012,13 +1012,13 @@ discard block |
||
| 1012 | 1012 | return $date; |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - /** |
|
| 1016 | - * Strips an absolute path to a file within the application |
|
| 1017 | - * to make the path relative to the application root path. |
|
| 1018 | - * |
|
| 1019 | - * @param string $path |
|
| 1020 | - * @return string |
|
| 1021 | - */ |
|
| 1015 | + /** |
|
| 1016 | + * Strips an absolute path to a file within the application |
|
| 1017 | + * to make the path relative to the application root path. |
|
| 1018 | + * |
|
| 1019 | + * @param string $path |
|
| 1020 | + * @return string |
|
| 1021 | + */ |
|
| 1022 | 1022 | public static function fileRelativize($path) |
| 1023 | 1023 | { |
| 1024 | 1024 | $path = str_replace('\\', '/', $path); |
@@ -1030,22 +1030,22 @@ discard block |
||
| 1030 | 1030 | |
| 1031 | 1031 | const JS_REGEX_JSON = 'json'; |
| 1032 | 1032 | |
| 1033 | - /** |
|
| 1034 | - * Takes a regular expression and attempts to convert it to |
|
| 1035 | - * its javascript equivalent. Returns an array containing the |
|
| 1036 | - * format string itself (without start and end characters), |
|
| 1037 | - * and the modifiers. |
|
| 1038 | - * |
|
| 1039 | - * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | - * |
|
| 1041 | - * <script> |
|
| 1042 | - * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | - * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | - * </script> |
|
| 1045 | - * |
|
| 1046 | - * @param string $regex |
|
| 1047 | - * @return array |
|
| 1048 | - */ |
|
| 1033 | + /** |
|
| 1034 | + * Takes a regular expression and attempts to convert it to |
|
| 1035 | + * its javascript equivalent. Returns an array containing the |
|
| 1036 | + * format string itself (without start and end characters), |
|
| 1037 | + * and the modifiers. |
|
| 1038 | + * |
|
| 1039 | + * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | + * |
|
| 1041 | + * <script> |
|
| 1042 | + * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | + * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | + * </script> |
|
| 1045 | + * |
|
| 1046 | + * @param string $regex |
|
| 1047 | + * @return array |
|
| 1048 | + */ |
|
| 1049 | 1049 | public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
| 1050 | 1050 | { |
| 1051 | 1051 | $regex = trim($regex); |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | - /** |
|
| 1095 | - * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | - * |
|
| 1097 | - * @param string $string |
|
| 1098 | - * @return string |
|
| 1099 | - */ |
|
| 1094 | + /** |
|
| 1095 | + * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | + * |
|
| 1097 | + * @param string $string |
|
| 1098 | + * @return string |
|
| 1099 | + */ |
|
| 1100 | 1100 | public static function stripUTFBom($string) |
| 1101 | 1101 | { |
| 1102 | 1102 | $boms = FileHelper::getUTFBOMs(); |
@@ -1111,13 +1111,13 @@ discard block |
||
| 1111 | 1111 | return $string; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - /** |
|
| 1115 | - * Converts a string to valid utf8, regardless |
|
| 1116 | - * of the string's encoding(s). |
|
| 1117 | - * |
|
| 1118 | - * @param string $string |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1114 | + /** |
|
| 1115 | + * Converts a string to valid utf8, regardless |
|
| 1116 | + * of the string's encoding(s). |
|
| 1117 | + * |
|
| 1118 | + * @param string $string |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | 1121 | public static function string2utf8($string) |
| 1122 | 1122 | { |
| 1123 | 1123 | if(!self::isStringASCII($string)) { |
@@ -1127,15 +1127,15 @@ discard block |
||
| 1127 | 1127 | return $string; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - /** |
|
| 1131 | - * Checks whether the specified string is an ASCII |
|
| 1132 | - * string, without any special or UTF8 characters. |
|
| 1133 | - * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | - * Any variable types other than strings are not. |
|
| 1135 | - * |
|
| 1136 | - * @param string $string |
|
| 1137 | - * @return boolean |
|
| 1138 | - */ |
|
| 1130 | + /** |
|
| 1131 | + * Checks whether the specified string is an ASCII |
|
| 1132 | + * string, without any special or UTF8 characters. |
|
| 1133 | + * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | + * Any variable types other than strings are not. |
|
| 1135 | + * |
|
| 1136 | + * @param string $string |
|
| 1137 | + * @return boolean |
|
| 1138 | + */ |
|
| 1139 | 1139 | public static function isStringASCII($string) |
| 1140 | 1140 | { |
| 1141 | 1141 | if($string === '' || $string === NULL) { |
@@ -1160,22 +1160,22 @@ discard block |
||
| 1160 | 1160 | return $url; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1164 | - * Calculates a percentage match of the source string with the target string. |
|
| 1165 | - * |
|
| 1166 | - * Options are: |
|
| 1167 | - * |
|
| 1168 | - * - maxLevenshtein, default: 10 |
|
| 1169 | - * Any levenshtein results above this value are ignored. |
|
| 1170 | - * |
|
| 1171 | - * - precision, default: 1 |
|
| 1172 | - * The precision of the percentage float value |
|
| 1173 | - * |
|
| 1174 | - * @param string $source |
|
| 1175 | - * @param string $target |
|
| 1176 | - * @param array $options |
|
| 1177 | - * @return float |
|
| 1178 | - */ |
|
| 1163 | + /** |
|
| 1164 | + * Calculates a percentage match of the source string with the target string. |
|
| 1165 | + * |
|
| 1166 | + * Options are: |
|
| 1167 | + * |
|
| 1168 | + * - maxLevenshtein, default: 10 |
|
| 1169 | + * Any levenshtein results above this value are ignored. |
|
| 1170 | + * |
|
| 1171 | + * - precision, default: 1 |
|
| 1172 | + * The precision of the percentage float value |
|
| 1173 | + * |
|
| 1174 | + * @param string $source |
|
| 1175 | + * @param string $target |
|
| 1176 | + * @param array $options |
|
| 1177 | + * @return float |
|
| 1178 | + */ |
|
| 1179 | 1179 | public static function matchString($source, $target, $options=array()) |
| 1180 | 1180 | { |
| 1181 | 1181 | $defaults = array( |
@@ -1259,14 +1259,14 @@ discard block |
||
| 1259 | 1259 | |
| 1260 | 1260 | const INTERVAL_SECONDS = 'seconds'; |
| 1261 | 1261 | |
| 1262 | - /** |
|
| 1263 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | - * of a date interval object and returns the value. |
|
| 1265 | - * |
|
| 1266 | - * @param \DateInterval $interval |
|
| 1267 | - * @param string $unit |
|
| 1268 | - * @return integer |
|
| 1269 | - */ |
|
| 1262 | + /** |
|
| 1263 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | + * of a date interval object and returns the value. |
|
| 1265 | + * |
|
| 1266 | + * @param \DateInterval $interval |
|
| 1267 | + * @param string $unit |
|
| 1268 | + * @return integer |
|
| 1269 | + */ |
|
| 1270 | 1270 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
| 1271 | 1271 | { |
| 1272 | 1272 | $total = $interval->format('%a'); |
@@ -1304,13 +1304,13 @@ discard block |
||
| 1304 | 1304 | 'Sunday' |
| 1305 | 1305 | ); |
| 1306 | 1306 | |
| 1307 | - /** |
|
| 1308 | - * Converts a date to the corresponding day name. |
|
| 1309 | - * |
|
| 1310 | - * @param \DateTime $date |
|
| 1311 | - * @param string $short |
|
| 1312 | - * @return string|NULL |
|
| 1313 | - */ |
|
| 1307 | + /** |
|
| 1308 | + * Converts a date to the corresponding day name. |
|
| 1309 | + * |
|
| 1310 | + * @param \DateTime $date |
|
| 1311 | + * @param string $short |
|
| 1312 | + * @return string|NULL |
|
| 1313 | + */ |
|
| 1314 | 1314 | public static function date2dayName(\DateTime $date, $short=false) |
| 1315 | 1315 | { |
| 1316 | 1316 | $day = $date->format('l'); |
@@ -1325,21 +1325,21 @@ discard block |
||
| 1325 | 1325 | return null; |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | - /** |
|
| 1329 | - * Retrieves a list of english day names. |
|
| 1330 | - * @return string[] |
|
| 1331 | - */ |
|
| 1328 | + /** |
|
| 1329 | + * Retrieves a list of english day names. |
|
| 1330 | + * @return string[] |
|
| 1331 | + */ |
|
| 1332 | 1332 | public static function getDayNamesInvariant() |
| 1333 | 1333 | { |
| 1334 | 1334 | return self::$daysInvariant; |
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | - /** |
|
| 1338 | - * Retrieves the day names list for the current locale. |
|
| 1339 | - * |
|
| 1340 | - * @param string $short |
|
| 1341 | - * @return string[] |
|
| 1342 | - */ |
|
| 1337 | + /** |
|
| 1338 | + * Retrieves the day names list for the current locale. |
|
| 1339 | + * |
|
| 1340 | + * @param string $short |
|
| 1341 | + * @return string[] |
|
| 1342 | + */ |
|
| 1343 | 1343 | public static function getDayNames($short=false) |
| 1344 | 1344 | { |
| 1345 | 1345 | if($short) { |
@@ -1399,16 +1399,16 @@ discard block |
||
| 1399 | 1399 | return $last; |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | - /** |
|
| 1403 | - * Splits a string into an array of all characters it is composed of. |
|
| 1404 | - * Unicode character safe. |
|
| 1405 | - * |
|
| 1406 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1407 | - * characters. |
|
| 1408 | - * |
|
| 1409 | - * @param string $string |
|
| 1410 | - * @return array |
|
| 1411 | - */ |
|
| 1402 | + /** |
|
| 1403 | + * Splits a string into an array of all characters it is composed of. |
|
| 1404 | + * Unicode character safe. |
|
| 1405 | + * |
|
| 1406 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1407 | + * characters. |
|
| 1408 | + * |
|
| 1409 | + * @param string $string |
|
| 1410 | + * @return array |
|
| 1411 | + */ |
|
| 1412 | 1412 | public static function string2array(string $string) : array |
| 1413 | 1413 | { |
| 1414 | 1414 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1419,12 +1419,12 @@ discard block |
||
| 1419 | 1419 | return array(); |
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - /** |
|
| 1423 | - * Checks whether the specified string contains HTML code. |
|
| 1424 | - * |
|
| 1425 | - * @param string $string |
|
| 1426 | - * @return boolean |
|
| 1427 | - */ |
|
| 1422 | + /** |
|
| 1423 | + * Checks whether the specified string contains HTML code. |
|
| 1424 | + * |
|
| 1425 | + * @param string $string |
|
| 1426 | + * @return boolean |
|
| 1427 | + */ |
|
| 1428 | 1428 | public static function isStringHTML(string $string) : bool |
| 1429 | 1429 | { |
| 1430 | 1430 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1439,18 +1439,18 @@ discard block |
||
| 1439 | 1439 | return false; |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | - /** |
|
| 1443 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1444 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1445 | - * are no calculated correctly. |
|
| 1446 | - * |
|
| 1447 | - * @param string $str |
|
| 1448 | - * @param int $width |
|
| 1449 | - * @param string $break |
|
| 1450 | - * @param bool $cut |
|
| 1451 | - * @return string |
|
| 1452 | - * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1453 | - */ |
|
| 1442 | + /** |
|
| 1443 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1444 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1445 | + * are no calculated correctly. |
|
| 1446 | + * |
|
| 1447 | + * @param string $str |
|
| 1448 | + * @param int $width |
|
| 1449 | + * @param string $break |
|
| 1450 | + * @param bool $cut |
|
| 1451 | + * @return string |
|
| 1452 | + * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1453 | + */ |
|
| 1454 | 1454 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
| 1455 | 1455 | { |
| 1456 | 1456 | $lines = explode($break, $str); |
@@ -1496,27 +1496,27 @@ discard block |
||
| 1496 | 1496 | return implode($break, $lines); |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | - /** |
|
| 1500 | - * Calculates the byte length of a string, taking into |
|
| 1501 | - * account any unicode characters. |
|
| 1502 | - * |
|
| 1503 | - * @param string $string |
|
| 1504 | - * @return int |
|
| 1505 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1506 | - */ |
|
| 1499 | + /** |
|
| 1500 | + * Calculates the byte length of a string, taking into |
|
| 1501 | + * account any unicode characters. |
|
| 1502 | + * |
|
| 1503 | + * @param string $string |
|
| 1504 | + * @return int |
|
| 1505 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1506 | + */ |
|
| 1507 | 1507 | public static function string2bytes($string) |
| 1508 | 1508 | { |
| 1509 | 1509 | return mb_strlen($string, '8bit'); |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | - /** |
|
| 1513 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1514 | - * |
|
| 1515 | - * WARNING: Not cryptographically safe. |
|
| 1516 | - * |
|
| 1517 | - * @param string $string |
|
| 1518 | - * @return string |
|
| 1519 | - */ |
|
| 1512 | + /** |
|
| 1513 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1514 | + * |
|
| 1515 | + * WARNING: Not cryptographically safe. |
|
| 1516 | + * |
|
| 1517 | + * @param string $string |
|
| 1518 | + * @return string |
|
| 1519 | + */ |
|
| 1520 | 1520 | public static function string2shortHash($string) |
| 1521 | 1521 | { |
| 1522 | 1522 | return hash('crc32', $string, false); |
@@ -1542,23 +1542,23 @@ discard block |
||
| 1542 | 1542 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * Parses the specified query string like the native |
|
| 1547 | - * function <code>parse_str</code>, without the key |
|
| 1548 | - * naming limitations. |
|
| 1549 | - * |
|
| 1550 | - * Using parse_str, dots or spaces in key names are |
|
| 1551 | - * replaced by underscores. This method keeps all names |
|
| 1552 | - * intact. |
|
| 1553 | - * |
|
| 1554 | - * It still uses the parse_str implementation as it |
|
| 1555 | - * is tested and tried, but fixes the parameter names |
|
| 1556 | - * after parsing, as needed. |
|
| 1557 | - * |
|
| 1558 | - * @param string $queryString |
|
| 1559 | - * @return array |
|
| 1560 | - * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1561 | - */ |
|
| 1545 | + /** |
|
| 1546 | + * Parses the specified query string like the native |
|
| 1547 | + * function <code>parse_str</code>, without the key |
|
| 1548 | + * naming limitations. |
|
| 1549 | + * |
|
| 1550 | + * Using parse_str, dots or spaces in key names are |
|
| 1551 | + * replaced by underscores. This method keeps all names |
|
| 1552 | + * intact. |
|
| 1553 | + * |
|
| 1554 | + * It still uses the parse_str implementation as it |
|
| 1555 | + * is tested and tried, but fixes the parameter names |
|
| 1556 | + * after parsing, as needed. |
|
| 1557 | + * |
|
| 1558 | + * @param string $queryString |
|
| 1559 | + * @return array |
|
| 1560 | + * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1561 | + */ |
|
| 1562 | 1562 | public static function parseQueryString(string $queryString) : array |
| 1563 | 1563 | { |
| 1564 | 1564 | // allow HTML entities notation |
@@ -1598,16 +1598,16 @@ discard block |
||
| 1598 | 1598 | $placeholders = array(); |
| 1599 | 1599 | foreach($paramNames as $paramName) |
| 1600 | 1600 | { |
| 1601 | - // create a unique placeholder name |
|
| 1602 | - $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1601 | + // create a unique placeholder name |
|
| 1602 | + $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1603 | 1603 | |
| 1604 | - // store the placeholder name to replace later |
|
| 1605 | - $table[$placeholder] = $paramName; |
|
| 1604 | + // store the placeholder name to replace later |
|
| 1605 | + $table[$placeholder] = $paramName; |
|
| 1606 | 1606 | |
| 1607 | - // add the placeholder to replace in the query string before parsing |
|
| 1608 | - $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1607 | + // add the placeholder to replace in the query string before parsing |
|
| 1608 | + $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1609 | 1609 | |
| 1610 | - $counter++; |
|
| 1610 | + $counter++; |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | // next challenge: replacing the parameter names by placeholders |
@@ -1634,23 +1634,23 @@ discard block |
||
| 1634 | 1634 | |
| 1635 | 1635 | foreach($parsed as $name => $value) |
| 1636 | 1636 | { |
| 1637 | - $keep[$table[$name]] = $value; |
|
| 1637 | + $keep[$table[$name]] = $value; |
|
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | 1640 | return $keep; |
| 1641 | 1641 | } |
| 1642 | 1642 | |
| 1643 | - /** |
|
| 1644 | - * Searches for needle in the specified string, and returns a list |
|
| 1645 | - * of all occurrences, including the matched string. The matched |
|
| 1646 | - * string is useful when doing a case insensitive search, as it |
|
| 1647 | - * shows the exact matched case of needle. |
|
| 1648 | - * |
|
| 1649 | - * @param string $needle |
|
| 1650 | - * @param string $haystack |
|
| 1651 | - * @param bool $caseInsensitive |
|
| 1652 | - * @return ConvertHelper_StringMatch[] |
|
| 1653 | - */ |
|
| 1643 | + /** |
|
| 1644 | + * Searches for needle in the specified string, and returns a list |
|
| 1645 | + * of all occurrences, including the matched string. The matched |
|
| 1646 | + * string is useful when doing a case insensitive search, as it |
|
| 1647 | + * shows the exact matched case of needle. |
|
| 1648 | + * |
|
| 1649 | + * @param string $needle |
|
| 1650 | + * @param string $haystack |
|
| 1651 | + * @param bool $caseInsensitive |
|
| 1652 | + * @return ConvertHelper_StringMatch[] |
|
| 1653 | + */ |
|
| 1654 | 1654 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1655 | 1655 | { |
| 1656 | 1656 | if($needle === '') { |
@@ -1676,14 +1676,14 @@ discard block |
||
| 1676 | 1676 | return $positions; |
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | - /** |
|
| 1680 | - * Like explode, but trims all entries, and removes |
|
| 1681 | - * empty entries from the resulting array. |
|
| 1682 | - * |
|
| 1683 | - * @param string $delimiter |
|
| 1684 | - * @param string $string |
|
| 1685 | - * @return string[] |
|
| 1686 | - */ |
|
| 1679 | + /** |
|
| 1680 | + * Like explode, but trims all entries, and removes |
|
| 1681 | + * empty entries from the resulting array. |
|
| 1682 | + * |
|
| 1683 | + * @param string $delimiter |
|
| 1684 | + * @param string $string |
|
| 1685 | + * @return string[] |
|
| 1686 | + */ |
|
| 1687 | 1687 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1688 | 1688 | { |
| 1689 | 1689 | if(empty($string) || empty($delimiter)) { |
@@ -1705,12 +1705,12 @@ discard block |
||
| 1705 | 1705 | |
| 1706 | 1706 | protected static $eolChars; |
| 1707 | 1707 | |
| 1708 | - /** |
|
| 1709 | - * Detects the most used end-of-line character in the subject string. |
|
| 1710 | - * |
|
| 1711 | - * @param string $str The string to check. |
|
| 1712 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1713 | - */ |
|
| 1708 | + /** |
|
| 1709 | + * Detects the most used end-of-line character in the subject string. |
|
| 1710 | + * |
|
| 1711 | + * @param string $str The string to check. |
|
| 1712 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1713 | + */ |
|
| 1714 | 1714 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1715 | 1715 | { |
| 1716 | 1716 | if(empty($subjectString)) { |
@@ -1722,27 +1722,27 @@ discard block |
||
| 1722 | 1722 | $cr = chr((int)hexdec('0d')); |
| 1723 | 1723 | $lf = chr((int)hexdec('0a')); |
| 1724 | 1724 | |
| 1725 | - self::$eolChars = array( |
|
| 1726 | - array( |
|
| 1727 | - 'char' => $cr.$lf, |
|
| 1728 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1729 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1730 | - ), |
|
| 1731 | - array( |
|
| 1732 | - 'char' => $lf.$cr, |
|
| 1733 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1734 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1735 | - ), |
|
| 1736 | - array( |
|
| 1737 | - 'char' => $lf, |
|
| 1738 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1739 | - 'description' => t('Line feed'), |
|
| 1740 | - ), |
|
| 1741 | - array( |
|
| 1742 | - 'char' => $cr, |
|
| 1743 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1744 | - 'description' => t('Carriage Return'), |
|
| 1745 | - ), |
|
| 1725 | + self::$eolChars = array( |
|
| 1726 | + array( |
|
| 1727 | + 'char' => $cr.$lf, |
|
| 1728 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1729 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1730 | + ), |
|
| 1731 | + array( |
|
| 1732 | + 'char' => $lf.$cr, |
|
| 1733 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1734 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1735 | + ), |
|
| 1736 | + array( |
|
| 1737 | + 'char' => $lf, |
|
| 1738 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1739 | + 'description' => t('Line feed'), |
|
| 1740 | + ), |
|
| 1741 | + array( |
|
| 1742 | + 'char' => $cr, |
|
| 1743 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1744 | + 'description' => t('Carriage Return'), |
|
| 1745 | + ), |
|
| 1746 | 1746 | ); |
| 1747 | 1747 | } |
| 1748 | 1748 | |
@@ -1770,13 +1770,13 @@ discard block |
||
| 1770 | 1770 | ); |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | - /** |
|
| 1774 | - * Removes the specified keys from the target array, |
|
| 1775 | - * if they exist. |
|
| 1776 | - * |
|
| 1777 | - * @param array $array |
|
| 1778 | - * @param array $keys |
|
| 1779 | - */ |
|
| 1773 | + /** |
|
| 1774 | + * Removes the specified keys from the target array, |
|
| 1775 | + * if they exist. |
|
| 1776 | + * |
|
| 1777 | + * @param array $array |
|
| 1778 | + * @param array $keys |
|
| 1779 | + */ |
|
| 1780 | 1780 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1781 | 1781 | { |
| 1782 | 1782 | foreach($keys as $key) |
@@ -1787,11 +1787,11 @@ discard block |
||
| 1787 | 1787 | } |
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | - /** |
|
| 1791 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1792 | - * @param mixed $value |
|
| 1793 | - * @return bool |
|
| 1794 | - */ |
|
| 1790 | + /** |
|
| 1791 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1792 | + * @param mixed $value |
|
| 1793 | + * @return bool |
|
| 1794 | + */ |
|
| 1795 | 1795 | public static function isInteger($value) : bool |
| 1796 | 1796 | { |
| 1797 | 1797 | if(is_int($value)) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $amount = substr_count($line, "\t") - $min; |
| 69 | 69 | $line = trim($line); |
| 70 | 70 | if ($amount >= 1) { |
| 71 | - $line = str_repeat("\t", $amount) . $line; |
|
| 71 | + $line = str_repeat("\t", $amount).$line; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $converted[] = $line; |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // specifically handle zero |
| 142 | 142 | if ($seconds <= 0) { |
| 143 | - return '0 ' . t('seconds'); |
|
| 143 | + return '0 '.t('seconds'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if($seconds < 1) { |
|
| 146 | + if ($seconds < 1) { |
|
| 147 | 147 | return t('less than a second'); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | foreach ($units as $def) { |
| 152 | 152 | $quot = intval($seconds / $def['value']); |
| 153 | 153 | if ($quot) { |
| 154 | - $item = $quot . ' '; |
|
| 154 | + $item = $quot.' '; |
|
| 155 | 155 | if (abs($quot) > 1) { |
| 156 | 156 | $item .= $def['plural']; |
| 157 | 157 | } else { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | return $last; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
| 171 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public static function duration2string($datefrom, $dateto = -1) |
| 187 | 187 | { |
| 188 | - if($datefrom instanceof \DateTime) { |
|
| 188 | + if ($datefrom instanceof \DateTime) { |
|
| 189 | 189 | $datefrom = ConvertHelper::date2timestamp($datefrom); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if($dateto instanceof \DateTime) { |
|
| 192 | + if ($dateto instanceof \DateTime) { |
|
| 193 | 193 | $dateto = ConvertHelper::date2timestamp($dateto); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $interval = ""; |
| 211 | 211 | |
| 212 | 212 | $future = false; |
| 213 | - if($difference < 0) { |
|
| 213 | + if ($difference < 0) { |
|
| 214 | 214 | $difference = $difference * -1; |
| 215 | 215 | $future = true; |
| 216 | 216 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $day = (int)date("j", $dateto); |
| 286 | 286 | $year = (int)date("Y", $datefrom); |
| 287 | 287 | |
| 288 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
| 288 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
| 289 | 289 | { |
| 290 | 290 | $months_difference++; |
| 291 | 291 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $datediff--; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if($future) { |
|
| 303 | + if ($future) { |
|
| 304 | 304 | $result = ($datediff == 1) ? t('In one month', $datediff) : t('In %1s months', $datediff); |
| 305 | 305 | } else { |
| 306 | 306 | $result = ($datediff == 1) ? t('One month ago', $datediff) : t('%1s months ago', $datediff); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | case "y": |
| 311 | 311 | $datediff = floor($difference / 60 / 60 / 24 / 365); |
| 312 | - if($future) { |
|
| 312 | + if ($future) { |
|
| 313 | 313 | $result = ($datediff == 1) ? t('In one year', $datediff) : t('In %1s years', $datediff); |
| 314 | 314 | } else { |
| 315 | 315 | $result = ($datediff == 1) ? t('One year ago', $datediff) : t('%1s years ago', $datediff); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | case "d": |
| 320 | 320 | $datediff = floor($difference / 60 / 60 / 24); |
| 321 | - if($future) { |
|
| 321 | + if ($future) { |
|
| 322 | 322 | $result = ($datediff == 1) ? t('In one day', $datediff) : t('In %1s days', $datediff); |
| 323 | 323 | } else { |
| 324 | 324 | $result = ($datediff == 1) ? t('One day ago', $datediff) : t('%1s days ago', $datediff); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | case "ww": |
| 329 | 329 | $datediff = floor($difference / 60 / 60 / 24 / 7); |
| 330 | - if($future) { |
|
| 330 | + if ($future) { |
|
| 331 | 331 | $result = ($datediff == 1) ? t('In one week', $datediff) : t('In %1s weeks', $datediff); |
| 332 | 332 | } else { |
| 333 | 333 | $result = ($datediff == 1) ? t('One week ago', $datediff) : t('%1s weeks ago', $datediff); |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | case "h": |
| 338 | 338 | $datediff = floor($difference / 60 / 60); |
| 339 | - if($future) { |
|
| 339 | + if ($future) { |
|
| 340 | 340 | $result = ($datediff == 1) ? t('In one hour', $datediff) : t('In %1s hours', $datediff); |
| 341 | 341 | } else { |
| 342 | 342 | $result = ($datediff == 1) ? t('One hour ago', $datediff) : t('%1s hours ago', $datediff); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | case "n": |
| 347 | 347 | $datediff = floor($difference / 60); |
| 348 | - if($future) { |
|
| 348 | + if ($future) { |
|
| 349 | 349 | $result = ($datediff == 1) ? t('In one minute', $datediff) : t('In %1s minutes', $datediff); |
| 350 | 350 | } else { |
| 351 | 351 | $result = ($datediff == 1) ? t('One minute ago', $datediff) : t('%1s minutes ago', $datediff); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | case "s": |
| 356 | 356 | $datediff = $difference; |
| 357 | - if($future) { |
|
| 357 | + if ($future) { |
|
| 358 | 358 | $result = ($datediff == 1) ? t('In one second', $datediff) : t('In %1s seconds', $datediff); |
| 359 | 359 | } else { |
| 360 | 360 | $result = ($datediff == 1) ? t('One second ago', $datediff) : t('%1s seconds ago', $datediff); |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | return $geshi->parse_code(); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - public static function highlight_xml($xml, $formatSource=false) |
|
| 380 | + public static function highlight_xml($xml, $formatSource = false) |
|
| 381 | 381 | { |
| 382 | - if($formatSource) |
|
| 382 | + if ($formatSource) |
|
| 383 | 383 | { |
| 384 | 384 | $dom = new \DOMDocument(); |
| 385 | 385 | $dom->loadXML($xml); |
@@ -417,22 +417,22 @@ discard block |
||
| 417 | 417 | $terabyte = $gigabyte * 1024; |
| 418 | 418 | |
| 419 | 419 | if (($bytes >= 0) && ($bytes < $kilobyte)) { |
| 420 | - return $bytes . ' ' . t('B'); |
|
| 420 | + return $bytes.' '.t('B'); |
|
| 421 | 421 | |
| 422 | 422 | } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
| 423 | - return round($bytes / $kilobyte, $precision) . ' ' . t('Kb'); |
|
| 423 | + return round($bytes / $kilobyte, $precision).' '.t('Kb'); |
|
| 424 | 424 | |
| 425 | 425 | } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
| 426 | - return round($bytes / $megabyte, $precision) . ' ' . t('Mb'); |
|
| 426 | + return round($bytes / $megabyte, $precision).' '.t('Mb'); |
|
| 427 | 427 | |
| 428 | 428 | } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
| 429 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Gb'); |
|
| 429 | + return round($bytes / $gigabyte, $precision).' '.t('Gb'); |
|
| 430 | 430 | |
| 431 | 431 | } elseif ($bytes >= $terabyte) { |
| 432 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Tb'); |
|
| 432 | + return round($bytes / $gigabyte, $precision).' '.t('Tb'); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - return $bytes . ' ' . t('B'); |
|
| 435 | + return $bytes.' '.t('B'); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -452,34 +452,34 @@ discard block |
||
| 452 | 452 | return $text; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
| 455 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
| 456 | 456 | |
| 457 | 457 | return $text; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - public static function var_dump($var, $html=true) |
|
| 460 | + public static function var_dump($var, $html = true) |
|
| 461 | 461 | { |
| 462 | 462 | $info = parseVariable($var); |
| 463 | 463 | |
| 464 | - if($html) { |
|
| 464 | + if ($html) { |
|
| 465 | 465 | return $info->toHTML(); |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return $info->toString(); |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - public static function print_r($var, $return=false, $html=true) |
|
| 471 | + public static function print_r($var, $return = false, $html = true) |
|
| 472 | 472 | { |
| 473 | 473 | $result = self::var_dump($var, $html); |
| 474 | 474 | |
| 475 | - if($html) { |
|
| 475 | + if ($html) { |
|
| 476 | 476 | $result = |
| 477 | 477 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
| 478 | 478 | $result. |
| 479 | 479 | '</pre>'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - if($return) { |
|
| 482 | + if ($return) { |
|
| 483 | 483 | return $result; |
| 484 | 484 | } |
| 485 | 485 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | public static function string2bool($string) |
| 501 | 501 | { |
| 502 | - if($string === '' || $string === null) { |
|
| 502 | + if ($string === '' || $string === null) { |
|
| 503 | 503 | return false; |
| 504 | 504 | } |
| 505 | 505 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
| 555 | 555 | { |
| 556 | 556 | $today = new \DateTime(); |
| 557 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 557 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 558 | 558 | $label = t('Today'); |
| 559 | 559 | } else { |
| 560 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
| 560 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
| 561 | 561 | if ($date->format('Y') != date('Y')) { |
| 562 | 562 | $label .= $date->format('Y'); |
| 563 | 563 | } |
@@ -648,28 +648,28 @@ discard block |
||
| 648 | 648 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
| 649 | 649 | |
| 650 | 650 | $stack = array(); |
| 651 | - foreach(self::$controlChars as $char) |
|
| 651 | + foreach (self::$controlChars as $char) |
|
| 652 | 652 | { |
| 653 | 653 | $tokens = explode('-', $char); |
| 654 | 654 | $start = $tokens[0]; |
| 655 | 655 | $end = $tokens[1]; |
| 656 | 656 | $prefix = substr($start, 0, 3); |
| 657 | 657 | $range = array(); |
| 658 | - foreach($hexAlphabet as $number) { |
|
| 658 | + foreach ($hexAlphabet as $number) { |
|
| 659 | 659 | $range[] = $prefix.$number; |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | $use = false; |
| 663 | - foreach($range as $number) { |
|
| 664 | - if($number == $start) { |
|
| 663 | + foreach ($range as $number) { |
|
| 664 | + if ($number == $start) { |
|
| 665 | 665 | $use = true; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if($use) { |
|
| 668 | + if ($use) { |
|
| 669 | 669 | $stack[] = $number; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if($number == $end) { |
|
| 672 | + if ($number == $end) { |
|
| 673 | 673 | break; |
| 674 | 674 | } |
| 675 | 675 | } |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | $chars = self::getControlCharactersAsHex(); |
| 691 | 691 | |
| 692 | 692 | $result = array(); |
| 693 | - foreach($chars as $char) { |
|
| 693 | + foreach ($chars as $char) { |
|
| 694 | 694 | $result[] = hex2bin($char); |
| 695 | 695 | } |
| 696 | 696 | |
@@ -708,14 +708,14 @@ discard block |
||
| 708 | 708 | $chars = self::getControlCharactersAsHex(); |
| 709 | 709 | |
| 710 | 710 | $result = array(); |
| 711 | - foreach($chars as $char) { |
|
| 711 | + foreach ($chars as $char) { |
|
| 712 | 712 | $result[] = '\u'.strtolower($char); |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | return $result; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | - protected static $controlChars = array( |
|
| 718 | + protected static $controlChars = array( |
|
| 719 | 719 | '0000-0008', // control chars |
| 720 | 720 | '000E-000F', // control chars |
| 721 | 721 | '0010-001F', // control chars |
@@ -737,19 +737,19 @@ discard block |
||
| 737 | 737 | */ |
| 738 | 738 | public static function stripControlCharacters(string $string) : string |
| 739 | 739 | { |
| 740 | - if(empty($string)) { |
|
| 740 | + if (empty($string)) { |
|
| 741 | 741 | return $string; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // create the regex from the unicode characters list |
| 745 | - if(!isset(self::$controlCharsRegex)) |
|
| 745 | + if (!isset(self::$controlCharsRegex)) |
|
| 746 | 746 | { |
| 747 | 747 | $chars = self::getControlCharactersAsHex(); |
| 748 | 748 | |
| 749 | 749 | // we use the notation \x{0000} to specify the unicode character key |
| 750 | 750 | // in the regular expression. |
| 751 | 751 | $stack = array(); |
| 752 | - foreach($chars as $char) { |
|
| 752 | + foreach ($chars as $char) { |
|
| 753 | 753 | $stack[] = '\x{'.$char.'}'; |
| 754 | 754 | } |
| 755 | 755 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | $ordInt = ord($octet); |
| 784 | 784 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
| 785 | 785 | $ordHex = base_convert($ordInt, 10, 16); |
| 786 | - $output .= '\x' . $ordHex; |
|
| 786 | + $output .= '\x'.$ordHex; |
|
| 787 | 787 | } |
| 788 | 788 | return $output; |
| 789 | 789 | } |
@@ -815,19 +815,19 @@ discard block |
||
| 815 | 815 | |
| 816 | 816 | protected static function convertScalarForComparison($scalar) |
| 817 | 817 | { |
| 818 | - if($scalar === '' || is_null($scalar)) { |
|
| 818 | + if ($scalar === '' || is_null($scalar)) { |
|
| 819 | 819 | return null; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - if(is_bool($scalar)) { |
|
| 822 | + if (is_bool($scalar)) { |
|
| 823 | 823 | return self::bool2string($scalar); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - if(is_array($scalar)) { |
|
| 826 | + if (is_array($scalar)) { |
|
| 827 | 827 | $scalar = md5(serialize($scalar)); |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - if($scalar !== null && !is_scalar($scalar)) { |
|
| 830 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
| 831 | 831 | throw new ConvertHelper_Exception( |
| 832 | 832 | 'Not a scalar value in comparison', |
| 833 | 833 | null, |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | public static function bool2string($boolean, bool $yesno = false) : string |
| 877 | 877 | { |
| 878 | 878 | // allow 'yes', 'true', 'no', 'false' string notations as well |
| 879 | - if(!is_bool($boolean)) { |
|
| 879 | + if (!is_bool($boolean)) { |
|
| 880 | 880 | $boolean = self::string2bool($boolean); |
| 881 | 881 | } |
| 882 | 882 | |
@@ -917,15 +917,15 @@ discard block |
||
| 917 | 917 | public static function array2attributeString($array) |
| 918 | 918 | { |
| 919 | 919 | $tokens = array(); |
| 920 | - foreach($array as $attr => $value) { |
|
| 921 | - if($value == '' || $value == null) { |
|
| 920 | + foreach ($array as $attr => $value) { |
|
| 921 | + if ($value == '' || $value == null) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | $tokens[] = $attr.'="'.$value.'"'; |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | - if(empty($tokens)) { |
|
| 928 | + if (empty($tokens)) { |
|
| 929 | 929 | return ''; |
| 930 | 930 | } |
| 931 | 931 | |
@@ -940,10 +940,10 @@ discard block |
||
| 940 | 940 | * @param string $string |
| 941 | 941 | * @return string |
| 942 | 942 | */ |
| 943 | - public static function string2attributeJS($string, $quoted=true) |
|
| 943 | + public static function string2attributeJS($string, $quoted = true) |
|
| 944 | 944 | { |
| 945 | 945 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
| 946 | - if($quoted) { |
|
| 946 | + if ($quoted) { |
|
| 947 | 947 | $converted = "'".$converted."'"; |
| 948 | 948 | } |
| 949 | 949 | |
@@ -961,11 +961,11 @@ discard block |
||
| 961 | 961 | */ |
| 962 | 962 | public static function isBoolean($value) : bool |
| 963 | 963 | { |
| 964 | - if(is_bool($value)) { |
|
| 964 | + if (is_bool($value)) { |
|
| 965 | 965 | return true; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - if(!is_scalar($value)) { |
|
| 968 | + if (!is_scalar($value)) { |
|
| 969 | 969 | return false; |
| 970 | 970 | } |
| 971 | 971 | |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | public static function array2styleString(array $subject) : string |
| 982 | 982 | { |
| 983 | 983 | $tokens = array(); |
| 984 | - foreach($subject as $name => $value) { |
|
| 984 | + foreach ($subject as $name => $value) { |
|
| 985 | 985 | $tokens[] = $name.':'.$value; |
| 986 | 986 | } |
| 987 | 987 | |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | * @param string $regex |
| 1047 | 1047 | * @return array |
| 1048 | 1048 | */ |
| 1049 | - public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
|
| 1049 | + public static function regex2js($regex, $return = self::JS_REGEX_OBJECT) |
|
| 1050 | 1050 | { |
| 1051 | 1051 | $regex = trim($regex); |
| 1052 | 1052 | $separator = substr($regex, 0, 1); |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | array_shift($parts); |
| 1055 | 1055 | |
| 1056 | 1056 | $modifiers = array_pop($parts); |
| 1057 | - if($modifiers == $separator) { |
|
| 1057 | + if ($modifiers == $separator) { |
|
| 1058 | 1058 | $modifiers = ''; |
| 1059 | 1059 | } |
| 1060 | 1060 | |
@@ -1070,14 +1070,14 @@ discard block |
||
| 1070 | 1070 | // convert the anchors that are not supported in js regexes |
| 1071 | 1071 | $format = str_replace(array('\\A', '\\Z', '\\z'), array('^', '$', ''), $format); |
| 1072 | 1072 | |
| 1073 | - if($return==self::JS_REGEX_JSON) { |
|
| 1073 | + if ($return == self::JS_REGEX_JSON) { |
|
| 1074 | 1074 | return json_encode(array( |
| 1075 | 1075 | 'format' => $format, |
| 1076 | 1076 | 'modifiers' => $modifiers |
| 1077 | 1077 | )); |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if(!empty($modifiers)) { |
|
| 1080 | + if (!empty($modifiers)) { |
|
| 1081 | 1081 | return sprintf( |
| 1082 | 1082 | 'new RegExp(%s, %s)', |
| 1083 | 1083 | json_encode($format), |
@@ -1100,10 +1100,10 @@ discard block |
||
| 1100 | 1100 | public static function stripUTFBom($string) |
| 1101 | 1101 | { |
| 1102 | 1102 | $boms = FileHelper::getUTFBOMs(); |
| 1103 | - foreach($boms as $bomChars) { |
|
| 1103 | + foreach ($boms as $bomChars) { |
|
| 1104 | 1104 | $length = mb_strlen($bomChars); |
| 1105 | 1105 | $text = mb_substr($string, 0, $length); |
| 1106 | - if($text==$bomChars) { |
|
| 1106 | + if ($text == $bomChars) { |
|
| 1107 | 1107 | return mb_substr($string, $length); |
| 1108 | 1108 | } |
| 1109 | 1109 | } |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | */ |
| 1121 | 1121 | public static function string2utf8($string) |
| 1122 | 1122 | { |
| 1123 | - if(!self::isStringASCII($string)) { |
|
| 1123 | + if (!self::isStringASCII($string)) { |
|
| 1124 | 1124 | return \ForceUTF8\Encoding::toUTF8($string); |
| 1125 | 1125 | } |
| 1126 | 1126 | |
@@ -1138,11 +1138,11 @@ discard block |
||
| 1138 | 1138 | */ |
| 1139 | 1139 | public static function isStringASCII($string) |
| 1140 | 1140 | { |
| 1141 | - if($string === '' || $string === NULL) { |
|
| 1141 | + if ($string === '' || $string === NULL) { |
|
| 1142 | 1142 | return true; |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - if(!is_string($string)) { |
|
| 1145 | + if (!is_string($string)) { |
|
| 1146 | 1146 | return false; |
| 1147 | 1147 | } |
| 1148 | 1148 | |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | * @param array $options |
| 1177 | 1177 | * @return float |
| 1178 | 1178 | */ |
| 1179 | - public static function matchString($source, $target, $options=array()) |
|
| 1179 | + public static function matchString($source, $target, $options = array()) |
|
| 1180 | 1180 | { |
| 1181 | 1181 | $defaults = array( |
| 1182 | 1182 | 'maxLevenshtein' => 10, |
@@ -1186,12 +1186,12 @@ discard block |
||
| 1186 | 1186 | $options = array_merge($defaults, $options); |
| 1187 | 1187 | |
| 1188 | 1188 | // avoid doing this via levenshtein |
| 1189 | - if($source == $target) { |
|
| 1189 | + if ($source == $target) { |
|
| 1190 | 1190 | return 100; |
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | $diff = levenshtein($source, $target); |
| 1194 | - if($diff > $options['maxLevenshtein']) { |
|
| 1194 | + if ($diff > $options['maxLevenshtein']) { |
|
| 1195 | 1195 | return 0; |
| 1196 | 1196 | } |
| 1197 | 1197 | |
@@ -1205,8 +1205,8 @@ discard block |
||
| 1205 | 1205 | |
| 1206 | 1206 | $offset = 0; |
| 1207 | 1207 | $keep = array(); |
| 1208 | - foreach($tokens as $token) { |
|
| 1209 | - if($interval->$token > 0) { |
|
| 1208 | + foreach ($tokens as $token) { |
|
| 1209 | + if ($interval->$token > 0) { |
|
| 1210 | 1210 | $keep = array_slice($tokens, $offset); |
| 1211 | 1211 | break; |
| 1212 | 1212 | } |
@@ -1215,16 +1215,16 @@ discard block |
||
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | $parts = array(); |
| 1218 | - foreach($keep as $token) |
|
| 1218 | + foreach ($keep as $token) |
|
| 1219 | 1219 | { |
| 1220 | 1220 | $value = $interval->$token; |
| 1221 | 1221 | $label = ''; |
| 1222 | 1222 | |
| 1223 | 1223 | $suffix = 'p'; |
| 1224 | - if($value == 1) { $suffix = 's'; } |
|
| 1224 | + if ($value == 1) { $suffix = 's'; } |
|
| 1225 | 1225 | $token .= $suffix; |
| 1226 | 1226 | |
| 1227 | - switch($token) { |
|
| 1227 | + switch ($token) { |
|
| 1228 | 1228 | case 'ys': $label = t('1 year'); break; |
| 1229 | 1229 | case 'yp': $label = t('%1$s years', $value); break; |
| 1230 | 1230 | case 'ms': $label = t('1 month'); break; |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $parts[] = $label; |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - if(count($parts) == 1) { |
|
| 1245 | + if (count($parts) == 1) { |
|
| 1246 | 1246 | return $parts[0]; |
| 1247 | 1247 | } |
| 1248 | 1248 | |
@@ -1267,23 +1267,23 @@ discard block |
||
| 1267 | 1267 | * @param string $unit |
| 1268 | 1268 | * @return integer |
| 1269 | 1269 | */ |
| 1270 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
|
| 1270 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) |
|
| 1271 | 1271 | { |
| 1272 | 1272 | $total = $interval->format('%a'); |
| 1273 | 1273 | if ($unit == self::INTERVAL_DAYS) { |
| 1274 | 1274 | return $total; |
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | - $total = ($total * 24) + ($interval->h ); |
|
| 1277 | + $total = ($total * 24) + ($interval->h); |
|
| 1278 | 1278 | if ($unit == self::INTERVAL_HOURS) { |
| 1279 | 1279 | return $total; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | - $total = ($total * 60) + ($interval->i ); |
|
| 1282 | + $total = ($total * 60) + ($interval->i); |
|
| 1283 | 1283 | if ($unit == self::INTERVAL_MINUTES) |
| 1284 | 1284 | return $total; |
| 1285 | 1285 | |
| 1286 | - $total = ($total * 60) + ($interval->s ); |
|
| 1286 | + $total = ($total * 60) + ($interval->s); |
|
| 1287 | 1287 | if ($unit == self::INTERVAL_SECONDS) |
| 1288 | 1288 | return $total; |
| 1289 | 1289 | |
@@ -1311,13 +1311,13 @@ discard block |
||
| 1311 | 1311 | * @param string $short |
| 1312 | 1312 | * @return string|NULL |
| 1313 | 1313 | */ |
| 1314 | - public static function date2dayName(\DateTime $date, $short=false) |
|
| 1314 | + public static function date2dayName(\DateTime $date, $short = false) |
|
| 1315 | 1315 | { |
| 1316 | 1316 | $day = $date->format('l'); |
| 1317 | 1317 | $invariant = self::getDayNamesInvariant(); |
| 1318 | 1318 | |
| 1319 | 1319 | $idx = array_search($day, $invariant); |
| 1320 | - if($idx !== false) { |
|
| 1320 | + if ($idx !== false) { |
|
| 1321 | 1321 | $localized = self::getDayNames($short); |
| 1322 | 1322 | return $localized[$idx]; |
| 1323 | 1323 | } |
@@ -1340,10 +1340,10 @@ discard block |
||
| 1340 | 1340 | * @param string $short |
| 1341 | 1341 | * @return string[] |
| 1342 | 1342 | */ |
| 1343 | - public static function getDayNames($short=false) |
|
| 1343 | + public static function getDayNames($short = false) |
|
| 1344 | 1344 | { |
| 1345 | - if($short) { |
|
| 1346 | - if(!isset(self::$daysShort)) { |
|
| 1345 | + if ($short) { |
|
| 1346 | + if (!isset(self::$daysShort)) { |
|
| 1347 | 1347 | self::$daysShort = array( |
| 1348 | 1348 | t('Mon'), |
| 1349 | 1349 | t('Tue'), |
@@ -1358,7 +1358,7 @@ discard block |
||
| 1358 | 1358 | return self::$daysShort; |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | - if(!isset(self::$days)) { |
|
| 1361 | + if (!isset(self::$days)) { |
|
| 1362 | 1362 | self::$days = array( |
| 1363 | 1363 | t('Monday'), |
| 1364 | 1364 | t('Tuesday'), |
@@ -1383,17 +1383,17 @@ discard block |
||
| 1383 | 1383 | */ |
| 1384 | 1384 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
| 1385 | 1385 | { |
| 1386 | - if(empty($list)) { |
|
| 1386 | + if (empty($list)) { |
|
| 1387 | 1387 | return ''; |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | - if(empty($conjunction)) { |
|
| 1390 | + if (empty($conjunction)) { |
|
| 1391 | 1391 | $conjunction = t('and'); |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | $last = array_pop($list); |
| 1395 | - if($list) { |
|
| 1396 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
| 1395 | + if ($list) { |
|
| 1396 | + return implode($sep, $list).$conjunction.' '.$last; |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | return $last; |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | public static function string2array(string $string) : array |
| 1413 | 1413 | { |
| 1414 | 1414 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
| 1415 | - if($result !== false) { |
|
| 1415 | + if ($result !== false) { |
|
| 1416 | 1416 | return $result; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
@@ -1427,12 +1427,12 @@ discard block |
||
| 1427 | 1427 | */ |
| 1428 | 1428 | public static function isStringHTML(string $string) : bool |
| 1429 | 1429 | { |
| 1430 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1430 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1431 | 1431 | return true; |
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | $decoded = html_entity_decode($string); |
| 1435 | - if($decoded !== $string) { |
|
| 1435 | + if ($decoded !== $string) { |
|
| 1436 | 1436 | return true; |
| 1437 | 1437 | } |
| 1438 | 1438 | |
@@ -1569,7 +1569,7 @@ discard block |
||
| 1569 | 1569 | // extract parameter names from the query string |
| 1570 | 1570 | $result = array(); |
| 1571 | 1571 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
| 1572 | - if(isset($result[1])) { |
|
| 1572 | + if (isset($result[1])) { |
|
| 1573 | 1573 | $paramNames = $result[1]; |
| 1574 | 1574 | } |
| 1575 | 1575 | |
@@ -1592,11 +1592,11 @@ discard block |
||
| 1592 | 1592 | // possible naming conflicts like having both parameters "foo.bar" |
| 1593 | 1593 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
| 1594 | 1594 | // to "foo_bar", one of the two would be replaced. |
| 1595 | - if($fixRequired) |
|
| 1595 | + if ($fixRequired) |
|
| 1596 | 1596 | { |
| 1597 | 1597 | $counter = 1; |
| 1598 | 1598 | $placeholders = array(); |
| 1599 | - foreach($paramNames as $paramName) |
|
| 1599 | + foreach ($paramNames as $paramName) |
|
| 1600 | 1600 | { |
| 1601 | 1601 | // create a unique placeholder name |
| 1602 | 1602 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -1626,13 +1626,13 @@ discard block |
||
| 1626 | 1626 | parse_str($queryString, $parsed); |
| 1627 | 1627 | |
| 1628 | 1628 | // do any of the parameter names need to be fixed? |
| 1629 | - if(!$fixRequired) { |
|
| 1629 | + if (!$fixRequired) { |
|
| 1630 | 1630 | return $parsed; |
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | $keep = array(); |
| 1634 | 1634 | |
| 1635 | - foreach($parsed as $name => $value) |
|
| 1635 | + foreach ($parsed as $name => $value) |
|
| 1636 | 1636 | { |
| 1637 | 1637 | $keep[$table[$name]] = $value; |
| 1638 | 1638 | } |
@@ -1651,14 +1651,14 @@ discard block |
||
| 1651 | 1651 | * @param bool $caseInsensitive |
| 1652 | 1652 | * @return ConvertHelper_StringMatch[] |
| 1653 | 1653 | */ |
| 1654 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
| 1654 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
| 1655 | 1655 | { |
| 1656 | - if($needle === '') { |
|
| 1656 | + if ($needle === '') { |
|
| 1657 | 1657 | return array(); |
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | $function = 'mb_strpos'; |
| 1661 | - if($caseInsensitive) { |
|
| 1661 | + if ($caseInsensitive) { |
|
| 1662 | 1662 | $function = 'mb_stripos'; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
@@ -1666,7 +1666,7 @@ discard block |
||
| 1666 | 1666 | $positions = array(); |
| 1667 | 1667 | $length = mb_strlen($needle); |
| 1668 | 1668 | |
| 1669 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1669 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1670 | 1670 | { |
| 1671 | 1671 | $match = mb_substr($haystack, $pos, $length); |
| 1672 | 1672 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1686,7 +1686,7 @@ discard block |
||
| 1686 | 1686 | */ |
| 1687 | 1687 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1688 | 1688 | { |
| 1689 | - if(empty($string) || empty($delimiter)) { |
|
| 1689 | + if (empty($string) || empty($delimiter)) { |
|
| 1690 | 1690 | return array(); |
| 1691 | 1691 | } |
| 1692 | 1692 | |
@@ -1694,8 +1694,8 @@ discard block |
||
| 1694 | 1694 | $tokens = array_map('trim', $tokens); |
| 1695 | 1695 | |
| 1696 | 1696 | $keep = array(); |
| 1697 | - foreach($tokens as $token) { |
|
| 1698 | - if($token !== '') { |
|
| 1697 | + foreach ($tokens as $token) { |
|
| 1698 | + if ($token !== '') { |
|
| 1699 | 1699 | $keep[] = $token; |
| 1700 | 1700 | } |
| 1701 | 1701 | } |
@@ -1713,11 +1713,11 @@ discard block |
||
| 1713 | 1713 | */ |
| 1714 | 1714 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1715 | 1715 | { |
| 1716 | - if(empty($subjectString)) { |
|
| 1716 | + if (empty($subjectString)) { |
|
| 1717 | 1717 | return null; |
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | - if(!isset(self::$eolChars)) |
|
| 1720 | + if (!isset(self::$eolChars)) |
|
| 1721 | 1721 | { |
| 1722 | 1722 | $cr = chr((int)hexdec('0d')); |
| 1723 | 1723 | $lf = chr((int)hexdec('0a')); |
@@ -1748,18 +1748,18 @@ discard block |
||
| 1748 | 1748 | |
| 1749 | 1749 | $max = 0; |
| 1750 | 1750 | $results = array(); |
| 1751 | - foreach(self::$eolChars as $def) |
|
| 1751 | + foreach (self::$eolChars as $def) |
|
| 1752 | 1752 | { |
| 1753 | 1753 | $amount = substr_count($subjectString, $def['char']); |
| 1754 | 1754 | |
| 1755 | - if($amount > $max) |
|
| 1755 | + if ($amount > $max) |
|
| 1756 | 1756 | { |
| 1757 | 1757 | $max = $amount; |
| 1758 | 1758 | $results[] = $def; |
| 1759 | 1759 | } |
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - if(empty($results)) { |
|
| 1762 | + if (empty($results)) { |
|
| 1763 | 1763 | return null; |
| 1764 | 1764 | } |
| 1765 | 1765 | |
@@ -1779,9 +1779,9 @@ discard block |
||
| 1779 | 1779 | */ |
| 1780 | 1780 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1781 | 1781 | { |
| 1782 | - foreach($keys as $key) |
|
| 1782 | + foreach ($keys as $key) |
|
| 1783 | 1783 | { |
| 1784 | - if(array_key_exists($key, $array)) { |
|
| 1784 | + if (array_key_exists($key, $array)) { |
|
| 1785 | 1785 | unset($array[$key]); |
| 1786 | 1786 | } |
| 1787 | 1787 | } |
@@ -1794,11 +1794,11 @@ discard block |
||
| 1794 | 1794 | */ |
| 1795 | 1795 | public static function isInteger($value) : bool |
| 1796 | 1796 | { |
| 1797 | - if(is_int($value)) { |
|
| 1797 | + if (is_int($value)) { |
|
| 1798 | 1798 | return true; |
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | - if(is_string($value)) { |
|
| 1801 | + if (is_string($value)) { |
|
| 1802 | 1802 | return preg_match('/\A\d+\z/', $value); |
| 1803 | 1803 | } |
| 1804 | 1804 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | return $this->setOption('separatorChar', $char); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function setTrailingNewline($useNewline=true) |
|
| 20 | + public function setTrailingNewline($useNewline = true) |
|
| 21 | 21 | { |
| 22 | 22 | return $this->setOption('trailingNewline', $useNewline); |
| 23 | 23 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $args = $args[0]; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $this->lines[] = '"' . implode('"'.$this->getOption('separatorChar').'"', $args) . '"'; |
|
| 41 | + $this->lines[] = '"'.implode('"'.$this->getOption('separatorChar').'"', $args).'"'; |
|
| 42 | 42 | |
| 43 | 43 | return $this; |
| 44 | 44 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $csv = implode(PHP_EOL, $this->lines); |
| 56 | 56 | |
| 57 | - if($this->getOption('trailingNewline')) { |
|
| 57 | + if ($this->getOption('trailingNewline')) { |
|
| 58 | 58 | $csv .= PHP_EOL; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | public function setOption($name, $value) |
| 67 | 67 | { |
| 68 | - if(!isset($this->options)) { |
|
| 68 | + if (!isset($this->options)) { |
|
| 69 | 69 | $this->options = $this->getDefaultOptions(); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function setOptions($options) |
| 77 | 77 | { |
| 78 | - foreach($options as $name => $value) { |
|
| 78 | + foreach ($options as $name => $value) { |
|
| 79 | 79 | $this->setOption($name, $value); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | return $this; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - public function getOption($name, $default=null) |
|
| 85 | + public function getOption($name, $default = null) |
|
| 86 | 86 | { |
| 87 | - if(!isset($this->options)) { |
|
| 87 | + if (!isset($this->options)) { |
|
| 88 | 88 | $this->options = $this->getDefaultOptions(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if(isset($this->options[$name])) { |
|
| 91 | + if (isset($this->options[$name])) { |
|
| 92 | 92 | return $this->options[$name]; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | public function hasOption($name) |
| 99 | 99 | { |
| 100 | - if(!isset($this->options)) { |
|
| 100 | + if (!isset($this->options)) { |
|
| 101 | 101 | $this->options = $this->getDefaultOptions(); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | public function getOptions() |
| 108 | 108 | { |
| 109 | - if(!isset($this->options)) { |
|
| 109 | + if (!isset($this->options)) { |
|
| 110 | 110 | $this->options = $this->getDefaultOptions(); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | public function isOption($name, $value) |
| 117 | 117 | { |
| 118 | - if($this->getOption($name) === $value) { |
|
| 118 | + if ($this->getOption($name) === $value) { |
|
| 119 | 119 | return true; |
| 120 | 120 | } |
| 121 | 121 | |