@@ -6,9 +6,9 @@ |
||
| 6 | 6 | |
| 7 | 7 | abstract class VariableInfo_Renderer_String extends VariableInfo_Renderer |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var mixed |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var mixed |
|
| 11 | + */ |
|
| 12 | 12 | protected $value; |
| 13 | 13 | |
| 14 | 14 | protected function init() |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | str_replace(' ', '-', $this->type) |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - if($this->info->getBoolOption('prepend-type') && !$this->info->isNull()) |
|
| 43 | + if ($this->info->getBoolOption('prepend-type') && !$this->info->isNull()) |
|
| 44 | 44 | { |
| 45 | 45 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->info->getType().'</span> '; |
| 46 | 46 | $converted = $typeLabel.' '.$converted; |
@@ -6,19 +6,19 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | abstract class VariableInfo_Renderer |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var mixed |
|
| 11 | - */ |
|
| 9 | + /** |
|
| 10 | + * @var mixed |
|
| 11 | + */ |
|
| 12 | 12 | protected $value; |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var VariableInfo |
|
| 16 | - */ |
|
| 14 | + /** |
|
| 15 | + * @var VariableInfo |
|
| 16 | + */ |
|
| 17 | 17 | protected $info; |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | 22 | protected $type; |
| 23 | 23 | |
| 24 | 24 | public function __construct(VariableInfo $info) |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | abstract protected function init(); |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Renders the value to the target format. |
|
| 36 | - * |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 34 | + /** |
|
| 35 | + * Renders the value to the target format. |
|
| 36 | + * |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | 39 | public function render() |
| 40 | 40 | { |
| 41 | 41 | return $this->_render(); |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | protected function detectAttributes() |
| 109 | 109 | { |
| 110 | - if(!$this->options['@attributes']) { |
|
| 110 | + if (!$this->options['@attributes']) { |
|
| 111 | 111 | return; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $attributes = $this->subject->attributes(); |
| 115 | 115 | |
| 116 | - if(!empty($attributes)) |
|
| 116 | + if (!empty($attributes)) |
|
| 117 | 117 | { |
| 118 | 118 | $this->result['@attributes'] = array_map('strval', iterator_to_array($attributes)); |
| 119 | 119 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $children = $this->subject; |
| 125 | 125 | $depth = $this->options['depth'] - 1; |
| 126 | 126 | |
| 127 | - if($depth <= 0) |
|
| 127 | + if ($depth <= 0) |
|
| 128 | 128 | { |
| 129 | 129 | $children = []; |
| 130 | 130 | } |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | $decorator->options = ['depth' => $depth] + $this->options; |
| 139 | 139 | |
| 140 | - if(isset($this->result[$name])) |
|
| 140 | + if (isset($this->result[$name])) |
|
| 141 | 141 | { |
| 142 | - if(!is_array($this->result[$name])) |
|
| 142 | + if (!is_array($this->result[$name])) |
|
| 143 | 143 | { |
| 144 | 144 | $this->result[$name] = [$this->result[$name]]; |
| 145 | 145 | } |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | // json encode non-whitespace element simplexml text values. |
| 159 | 159 | $text = trim((string)$this->subject); |
| 160 | 160 | |
| 161 | - if(strlen($text)) |
|
| 161 | + if (strlen($text)) |
|
| 162 | 162 | { |
| 163 | - if($this->options['@text']) |
|
| 163 | + if ($this->options['@text']) |
|
| 164 | 164 | { |
| 165 | 165 | $this->result['@text'] = $text; |
| 166 | 166 | } |
@@ -145,8 +145,7 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $this->result[$name][] = $decorator; |
| 148 | - } |
|
| 149 | - else |
|
| 148 | + } else |
|
| 150 | 149 | { |
| 151 | 150 | $this->result[$name] = $decorator; |
| 152 | 151 | } |
@@ -163,8 +162,7 @@ discard block |
||
| 163 | 162 | if($this->options['@text']) |
| 164 | 163 | { |
| 165 | 164 | $this->result['@text'] = $text; |
| 166 | - } |
|
| 167 | - else |
|
| 165 | + } else |
|
| 168 | 166 | { |
| 169 | 167 | $this->result = $text; |
| 170 | 168 | } |
@@ -21,25 +21,25 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class XMLHelper_Converter_Decorator implements \JsonSerializable |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var \SimpleXMLElement |
|
| 26 | - */ |
|
| 24 | + /** |
|
| 25 | + * @var \SimpleXMLElement |
|
| 26 | + */ |
|
| 27 | 27 | private $subject; |
| 28 | 28 | |
| 29 | 29 | public const DEF_DEPTH = 512; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | 34 | private $options = array( |
| 35 | 35 | '@attributes' => true, |
| 36 | 36 | '@text' => true, |
| 37 | 37 | 'depth' => self::DEF_DEPTH |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var array|string|null |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var array|string|null |
|
| 42 | + */ |
|
| 43 | 43 | protected $result = array(); |
| 44 | 44 | |
| 45 | 45 | public function __construct(\SimpleXMLElement $element) |
@@ -47,36 +47,36 @@ discard block |
||
| 47 | 47 | $this->subject = $element; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Whether to use the `@attributes` key to store element attributes. |
|
| 52 | - * |
|
| 53 | - * @param bool $bool |
|
| 54 | - * @return XMLHelper_Converter_Decorator |
|
| 55 | - */ |
|
| 50 | + /** |
|
| 51 | + * Whether to use the `@attributes` key to store element attributes. |
|
| 52 | + * |
|
| 53 | + * @param bool $bool |
|
| 54 | + * @return XMLHelper_Converter_Decorator |
|
| 55 | + */ |
|
| 56 | 56 | public function useAttributes(bool $bool) : XMLHelper_Converter_Decorator |
| 57 | 57 | { |
| 58 | 58 | $this->options['@attributes'] = (bool)$bool; |
| 59 | 59 | return $this; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Whether to use the `@text` key to store the node text. |
|
| 64 | - * |
|
| 65 | - * @param bool $bool |
|
| 66 | - * @return XMLHelper_Converter_Decorator |
|
| 67 | - */ |
|
| 62 | + /** |
|
| 63 | + * Whether to use the `@text` key to store the node text. |
|
| 64 | + * |
|
| 65 | + * @param bool $bool |
|
| 66 | + * @return XMLHelper_Converter_Decorator |
|
| 67 | + */ |
|
| 68 | 68 | public function useText(bool $bool) : XMLHelper_Converter_Decorator |
| 69 | 69 | { |
| 70 | 70 | $this->options['@text'] = (bool)$bool; |
| 71 | 71 | return $this; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Set the maximum depth to parse in the document. |
|
| 76 | - * |
|
| 77 | - * @param int $depth |
|
| 78 | - * @return XMLHelper_Converter_Decorator |
|
| 79 | - */ |
|
| 74 | + /** |
|
| 75 | + * Set the maximum depth to parse in the document. |
|
| 76 | + * |
|
| 77 | + * @param int $depth |
|
| 78 | + * @return XMLHelper_Converter_Decorator |
|
| 79 | + */ |
|
| 80 | 80 | public function setDepth(int $depth) : XMLHelper_Converter_Decorator |
| 81 | 81 | { |
| 82 | 82 | $this->options['depth'] = (int)max(0, $depth); |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | |
| 143 | 143 | protected function getInfoKey(string $name) : string |
| 144 | 144 | { |
| 145 | - if(isset($this->info[$name])) { |
|
| 145 | + if (isset($this->info[$name])) { |
|
| 146 | 146 | return (string)$this->info[$name]; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -19,51 +19,51 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class RequestHelper_Response |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var RequestHelper |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var RequestHelper |
|
| 24 | + */ |
|
| 25 | 25 | protected $request; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | 30 | protected $body = ''; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | 35 | protected $info; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | 40 | protected $isError = false; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $errorMessage = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var integer |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var integer |
|
| 49 | + */ |
|
| 50 | 50 | protected $errorCode = 0; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param RequestHelper $helper |
|
| 54 | - * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * @param RequestHelper $helper |
|
| 54 | + * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | + */ |
|
| 56 | 56 | public function __construct(RequestHelper $helper, array $info) |
| 57 | 57 | { |
| 58 | 58 | $this->request = $helper; |
| 59 | 59 | $this->info = $info; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Retrieves the request instance that initiated the request. |
|
| 64 | - * |
|
| 65 | - * @return RequestHelper |
|
| 66 | - */ |
|
| 62 | + /** |
|
| 63 | + * Retrieves the request instance that initiated the request. |
|
| 64 | + * |
|
| 65 | + * @return RequestHelper |
|
| 66 | + */ |
|
| 67 | 67 | public function getRequest() : RequestHelper |
| 68 | 68 | { |
| 69 | 69 | return $this->request; |
@@ -84,79 +84,79 @@ discard block |
||
| 84 | 84 | return $this; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Whether an error occurred in the request. |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 87 | + /** |
|
| 88 | + * Whether an error occurred in the request. |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | 91 | public function isError() : bool |
| 92 | 92 | { |
| 93 | 93 | return $this->isError; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Whether the request timed out. |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 96 | + /** |
|
| 97 | + * Whether the request timed out. |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | 100 | public function isTimeout() : bool |
| 101 | 101 | { |
| 102 | 102 | return $this->errorCode === RequestHelper_CURL::OPERATION_TIMEDOUT; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Retrieves the native error message, if an error occurred. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * Retrieves the native error message, if an error occurred. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public function getErrorMessage() : string |
| 110 | 110 | { |
| 111 | 111 | return $this->errorMessage; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Retrieves the native CURL error code, if an error occurred. |
|
| 116 | - * @return int |
|
| 117 | - * @see RequestHelper_CURL For a list of error codes. |
|
| 118 | - */ |
|
| 114 | + /** |
|
| 115 | + * Retrieves the native CURL error code, if an error occurred. |
|
| 116 | + * @return int |
|
| 117 | + * @see RequestHelper_CURL For a list of error codes. |
|
| 118 | + */ |
|
| 119 | 119 | public function getErrorCode() : int |
| 120 | 120 | { |
| 121 | 121 | return $this->errorCode; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Retrieves the full body of the request. |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 124 | + /** |
|
| 125 | + * Retrieves the full body of the request. |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | 129 | public function getRequestBody() : string |
| 130 | 130 | { |
| 131 | 131 | return $this->request->getBody(); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Retrieves the body of the response, if any. |
|
| 136 | - * |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 134 | + /** |
|
| 135 | + * Retrieves the body of the response, if any. |
|
| 136 | + * |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | 139 | public function getResponseBody() : string |
| 140 | 140 | { |
| 141 | 141 | return $this->body; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * The response HTTP code. |
|
| 146 | - * |
|
| 147 | - * @return int The code, or 0 if none was sent (on error). |
|
| 148 | - */ |
|
| 144 | + /** |
|
| 145 | + * The response HTTP code. |
|
| 146 | + * |
|
| 147 | + * @return int The code, or 0 if none was sent (on error). |
|
| 148 | + */ |
|
| 149 | 149 | public function getCode() : int |
| 150 | 150 | { |
| 151 | 151 | return intval($this->getInfoKey('http_code')); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Retrieves the actual headers that were sent in the request: |
|
| 156 | - * one header by entry in the indexed array. |
|
| 157 | - * |
|
| 158 | - * @return array |
|
| 159 | - */ |
|
| 154 | + /** |
|
| 155 | + * Retrieves the actual headers that were sent in the request: |
|
| 156 | + * one header by entry in the indexed array. |
|
| 157 | + * |
|
| 158 | + * @return array |
|
| 159 | + */ |
|
| 160 | 160 | public function getHeaders() : array |
| 161 | 161 | { |
| 162 | 162 | return ConvertHelper::explodeTrim("\n", $this->getInfoKey('request_header')); |
@@ -32,23 +32,23 @@ |
||
| 32 | 32 | $this->info = $info; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Enables the authentication information in the URL, |
|
| 37 | - * if a username and password are present. |
|
| 38 | - * |
|
| 39 | - * @param bool $enable Whether to turn it on or off. |
|
| 40 | - * @return URLInfo_Normalizer |
|
| 41 | - */ |
|
| 35 | + /** |
|
| 36 | + * Enables the authentication information in the URL, |
|
| 37 | + * if a username and password are present. |
|
| 38 | + * |
|
| 39 | + * @param bool $enable Whether to turn it on or off. |
|
| 40 | + * @return URLInfo_Normalizer |
|
| 41 | + */ |
|
| 42 | 42 | public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Retrieves the normalized URL. |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 48 | + /** |
|
| 49 | + * Retrieves the normalized URL. |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | 52 | public function normalize() : string |
| 53 | 53 | { |
| 54 | 54 | $method = 'normalize_'.$this->info->getType(); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param bool $enable Whether to turn it on or off. |
| 40 | 40 | * @return URLInfo_Normalizer |
| 41 | 41 | */ |
| 42 | - public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
|
| 42 | + public function enableAuth(bool $enable = true) : URLInfo_Normalizer |
|
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
@@ -86,48 +86,48 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | protected function renderAuth(string $normalized) : string |
| 88 | 88 | { |
| 89 | - if(!$this->info->hasUsername() || !$this->auth) { |
|
| 89 | + if (!$this->info->hasUsername() || !$this->auth) { |
|
| 90 | 90 | return $normalized; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return $normalized . urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 93 | + return $normalized.urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function renderPort(string $normalized) : string |
| 97 | 97 | { |
| 98 | - if(!$this->info->hasPort()) { |
|
| 98 | + if (!$this->info->hasPort()) { |
|
| 99 | 99 | return $normalized; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return $normalized . ':'.$this->info->getPort(); |
|
| 102 | + return $normalized.':'.$this->info->getPort(); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | protected function renderPath(string $normalized) : string |
| 106 | 106 | { |
| 107 | - if(!$this->info->hasPath()) { |
|
| 107 | + if (!$this->info->hasPath()) { |
|
| 108 | 108 | return $normalized; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return $normalized . $this->info->getPath(); |
|
| 111 | + return $normalized.$this->info->getPath(); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | protected function renderParams(string $normalized) : string |
| 115 | 115 | { |
| 116 | 116 | $params = $this->info->getParams(); |
| 117 | 117 | |
| 118 | - if(empty($params)) { |
|
| 118 | + if (empty($params)) { |
|
| 119 | 119 | return $normalized; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return $normalized . '?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 122 | + return $normalized.'?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | protected function renderFragment(string $normalized) : string |
| 126 | 126 | { |
| 127 | - if(!$this->info->hasFragment()) { |
|
| 127 | + if (!$this->info->hasFragment()) { |
|
| 128 | 128 | return $normalized; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - return $normalized . '#'.$this->info->getFragment(); |
|
| 131 | + return $normalized.'#'.$this->info->getFragment(); |
|
| 132 | 132 | } |
| 133 | 133 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected static function init() : void |
| 46 | 46 | { |
| 47 | - if(!empty(self::$sizes)) { |
|
| 47 | + if (!empty(self::$sizes)) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | self::addSize('b', 1, 1, t('B'), t('Byte'), t('Bytes')); |
| 64 | 64 | |
| 65 | - if(class_exists('AppLocalize\Localization')) |
|
| 65 | + if (class_exists('AppLocalize\Localization')) |
|
| 66 | 66 | { |
| 67 | 67 | \AppLocalize\Localization::onLocaleChanged(array(self::class, 'handle_localeChanged')); |
| 68 | 68 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $name = strtolower($name); |
| 133 | 133 | |
| 134 | - if(isset(self::$sizes[$name])) { |
|
| 134 | + if (isset(self::$sizes[$name])) { |
|
| 135 | 135 | return self::$sizes[$name]; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | $result = array(); |
| 175 | 175 | |
| 176 | - foreach(self::$sizes as $size) |
|
| 176 | + foreach (self::$sizes as $size) |
|
| 177 | 177 | { |
| 178 | - if($size->getBase() === $base) { |
|
| 178 | + if ($size->getBase() === $base) { |
|
| 179 | 179 | $result[] = $size; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -30,17 +30,17 @@ discard block |
||
| 30 | 30 | public const BASE_10 = 1000; |
| 31 | 31 | public const BASE_2 = 1024; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var array<string,ConvertHelper_StorageSizeEnum_Size> |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var array<string,ConvertHelper_StorageSizeEnum_Size> |
|
| 35 | + */ |
|
| 36 | 36 | protected static $sizes = array(); |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initializes the supported unit notations, and |
|
| 40 | - * how they are supposed to be calculated. |
|
| 41 | - * |
|
| 42 | - * @see ConvertHelper_SizeNotation::parseSize() |
|
| 43 | - */ |
|
| 38 | + /** |
|
| 39 | + * Initializes the supported unit notations, and |
|
| 40 | + * how they are supposed to be calculated. |
|
| 41 | + * |
|
| 42 | + * @see ConvertHelper_SizeNotation::parseSize() |
|
| 43 | + */ |
|
| 44 | 44 | protected static function init() : void |
| 45 | 45 | { |
| 46 | 46 | if(!empty(self::$sizes)) { |
@@ -67,28 +67,28 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Called whenever the application locale is changed, |
|
| 72 | - * to reset the size definitions so the labels get |
|
| 73 | - * translated to the new locale. |
|
| 74 | - */ |
|
| 70 | + /** |
|
| 71 | + * Called whenever the application locale is changed, |
|
| 72 | + * to reset the size definitions so the labels get |
|
| 73 | + * translated to the new locale. |
|
| 74 | + */ |
|
| 75 | 75 | public static function handle_localeChanged() : void |
| 76 | 76 | { |
| 77 | 77 | self::$sizes = array(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Adds a storage size to the internal collection. |
|
| 82 | - * |
|
| 83 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 84 | - * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 85 | - * @param int $exponent The multiplier of the base to get the byte value |
|
| 86 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 87 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 88 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 89 | - * |
|
| 90 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 91 | - */ |
|
| 80 | + /** |
|
| 81 | + * Adds a storage size to the internal collection. |
|
| 82 | + * |
|
| 83 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 84 | + * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 85 | + * @param int $exponent The multiplier of the base to get the byte value |
|
| 86 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 87 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 88 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 89 | + * |
|
| 90 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 91 | + */ |
|
| 92 | 92 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) : void |
| 93 | 93 | { |
| 94 | 94 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | ); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Retrieves all known sizes. |
|
| 106 | - * |
|
| 107 | - * @return ConvertHelper_StorageSizeEnum_Size[] |
|
| 108 | - */ |
|
| 104 | + /** |
|
| 105 | + * Retrieves all known sizes. |
|
| 106 | + * |
|
| 107 | + * @return ConvertHelper_StorageSizeEnum_Size[] |
|
| 108 | + */ |
|
| 109 | 109 | public static function getSizes() : array |
| 110 | 110 | { |
| 111 | 111 | self::init(); |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | return array_values(self::$sizes); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Retrieves a size definition instance by its name. |
|
| 118 | - * |
|
| 119 | - * @param string $name Case-insensitive. For example "kb", "MiB"... |
|
| 120 | - * @throws ConvertHelper_Exception |
|
| 121 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 122 | - * |
|
| 123 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 124 | - */ |
|
| 116 | + /** |
|
| 117 | + * Retrieves a size definition instance by its name. |
|
| 118 | + * |
|
| 119 | + * @param string $name Case-insensitive. For example "kb", "MiB"... |
|
| 120 | + * @throws ConvertHelper_Exception |
|
| 121 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 122 | + * |
|
| 123 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 124 | + */ |
|
| 125 | 125 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
| 126 | 126 | { |
| 127 | 127 | self::init(); |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | ); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 148 | - * @return string[] |
|
| 149 | - */ |
|
| 146 | + /** |
|
| 147 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 148 | + * @return string[] |
|
| 149 | + */ |
|
| 150 | 150 | public static function getSizeNames() : array |
| 151 | 151 | { |
| 152 | 152 | self::init(); |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | return array_keys(self::$sizes); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Retrieves all available storage sizes for the specified |
|
| 159 | - * base value. |
|
| 160 | - * |
|
| 161 | - * @param int $base |
|
| 162 | - * @return ConvertHelper_StorageSizeEnum_Size[] |
|
| 163 | - * |
|
| 164 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 165 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 166 | - */ |
|
| 157 | + /** |
|
| 158 | + * Retrieves all available storage sizes for the specified |
|
| 159 | + * base value. |
|
| 160 | + * |
|
| 161 | + * @param int $base |
|
| 162 | + * @return ConvertHelper_StorageSizeEnum_Size[] |
|
| 163 | + * |
|
| 164 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 165 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 166 | + */ |
|
| 167 | 167 | public static function getSizesByBase(int $base) : array |
| 168 | 168 | { |
| 169 | 169 | self::init(); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param bool $enable |
| 58 | 58 | * @return ConvertHelper_TabsNormalizer |
| 59 | 59 | */ |
| 60 | - public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
|
| 60 | + public function convertTabsToSpaces(bool $enable = true) : ConvertHelper_TabsNormalizer |
|
| 61 | 61 | { |
| 62 | 62 | $this->tabs2spaces = $enable; |
| 63 | 63 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $result = $this->_normalize(); |
| 96 | 96 | |
| 97 | - if($this->tabs2spaces) |
|
| 97 | + if ($this->tabs2spaces) |
|
| 98 | 98 | { |
| 99 | 99 | $result = ConvertHelper::tabs2spaces($result, $this->tabSize); |
| 100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $eol = ConvertHelper::detectEOLCharacter($string); |
| 110 | 110 | |
| 111 | - if($eol !== null) |
|
| 111 | + if ($eol !== null) |
|
| 112 | 112 | { |
| 113 | 113 | $this->eol = $eol->getCharacter(); |
| 114 | 114 | } |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $converted = array(); |
| 128 | 128 | |
| 129 | - foreach($this->lines as $line) |
|
| 129 | + foreach ($this->lines as $line) |
|
| 130 | 130 | { |
| 131 | 131 | $amount = substr_count($line, "\t") - $this->min; |
| 132 | 132 | |
| 133 | 133 | $line = trim($line, "\n\r\t"); |
| 134 | 134 | |
| 135 | - if($amount >= 1) |
|
| 135 | + if ($amount >= 1) |
|
| 136 | 136 | { |
| 137 | - $line = str_repeat("\t", $amount) . $line; |
|
| 137 | + $line = str_repeat("\t", $amount).$line; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $converted[] = $line; |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function countOccurrences() : void |
| 151 | 151 | { |
| 152 | - foreach($this->lines as $line) |
|
| 152 | + foreach ($this->lines as $line) |
|
| 153 | 153 | { |
| 154 | 154 | $amount = substr_count($line, "\t"); |
| 155 | 155 | |
| 156 | - if($amount > $this->max) |
|
| 156 | + if ($amount > $this->max) |
|
| 157 | 157 | { |
| 158 | 158 | $this->max = $amount; |
| 159 | 159 | continue; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if($amount > 0 && $amount < $this->min) |
|
| 162 | + if ($amount > 0 && $amount < $this->min) |
|
| 163 | 163 | { |
| 164 | 164 | $this->min = $amount; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if($this->min === PHP_INT_MAX) { |
|
| 168 | + if ($this->min === PHP_INT_MAX) { |
|
| 169 | 169 | $this->min = 0; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -20,43 +20,43 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class ConvertHelper_TabsNormalizer |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var integer |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var integer |
|
| 25 | + */ |
|
| 26 | 26 | protected $max = 0; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var integer |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var integer |
|
| 30 | + */ |
|
| 31 | 31 | protected $min = PHP_INT_MAX; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var bool |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var bool |
|
| 35 | + */ |
|
| 36 | 36 | protected $tabs2spaces = false; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var string[] |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var string[] |
|
| 40 | + */ |
|
| 41 | 41 | protected $lines = array(); |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $eol = ''; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var integer |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var integer |
|
| 50 | + */ |
|
| 51 | 51 | protected $tabSize = 4; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Whether to enable or disable the conversion |
|
| 55 | - * of tabs to spaces. |
|
| 56 | - * |
|
| 57 | - * @param bool $enable |
|
| 58 | - * @return ConvertHelper_TabsNormalizer |
|
| 59 | - */ |
|
| 53 | + /** |
|
| 54 | + * Whether to enable or disable the conversion |
|
| 55 | + * of tabs to spaces. |
|
| 56 | + * |
|
| 57 | + * @param bool $enable |
|
| 58 | + * @return ConvertHelper_TabsNormalizer |
|
| 59 | + */ |
|
| 60 | 60 | public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
| 61 | 61 | { |
| 62 | 62 | $this->tabs2spaces = $enable; |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | return $this; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Sets the size of a tab, in spaces. Used to convert tabs |
|
| 69 | - * from spaces and the other way around. Defaults to 4. |
|
| 70 | - * |
|
| 71 | - * @param int $amountSpaces |
|
| 72 | - * @return ConvertHelper_TabsNormalizer |
|
| 73 | - */ |
|
| 67 | + /** |
|
| 68 | + * Sets the size of a tab, in spaces. Used to convert tabs |
|
| 69 | + * from spaces and the other way around. Defaults to 4. |
|
| 70 | + * |
|
| 71 | + * @param int $amountSpaces |
|
| 72 | + * @return ConvertHelper_TabsNormalizer |
|
| 73 | + */ |
|
| 74 | 74 | public function setTabSize(int $amountSpaces) : ConvertHelper_TabsNormalizer |
| 75 | 75 | { |
| 76 | 76 | $this->tabSize = $amountSpaces; |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | return $this; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Normalizes tabs in the specified string by indenting everything |
|
| 83 | - * back to the minimum tab distance. With the second parameter, |
|
| 84 | - * tabs can optionally be converted to spaces as well (recommended |
|
| 85 | - * for HTML output). |
|
| 86 | - * |
|
| 87 | - * @param string $string |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 81 | + /** |
|
| 82 | + * Normalizes tabs in the specified string by indenting everything |
|
| 83 | + * back to the minimum tab distance. With the second parameter, |
|
| 84 | + * tabs can optionally be converted to spaces as well (recommended |
|
| 85 | + * for HTML output). |
|
| 86 | + * |
|
| 87 | + * @param string $string |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | 90 | public function normalize(string $string) : string |
| 91 | 91 | { |
| 92 | 92 | $this->splitLines($string); |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | return implode($this->eol, $converted); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Finds out the minimum and maximum amount of |
|
| 148 | - * tabs in the string. |
|
| 149 | - */ |
|
| 146 | + /** |
|
| 147 | + * Finds out the minimum and maximum amount of |
|
| 148 | + * tabs in the string. |
|
| 149 | + */ |
|
| 150 | 150 | protected function countOccurrences() : void |
| 151 | 151 | { |
| 152 | 152 | foreach($this->lines as $line) |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
| 95 | 95 | { |
| 96 | - if(!in_array($type, $this->selected)) { |
|
| 96 | + if (!in_array($type, $this->selected)) { |
|
| 97 | 97 | $this->selected[] = $type; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $selected = $this->selected; |
| 111 | 111 | |
| 112 | - if(empty($this->selected)) |
|
| 112 | + if (empty($this->selected)) |
|
| 113 | 113 | { |
| 114 | 114 | $selected = array( |
| 115 | 115 | self::CHARS_WHITESPACE, |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $result = array(); |
| 121 | 121 | |
| 122 | - foreach($selected as $type) |
|
| 122 | + foreach ($selected as $type) |
|
| 123 | 123 | { |
| 124 | - if(isset($this->characters[$type])) |
|
| 124 | + if (isset($this->characters[$type])) |
|
| 125 | 125 | { |
| 126 | 126 | $result = array_merge($result, $this->characters[$type]); |
| 127 | 127 | } |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | ) |
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @var string[] |
|
| 76 | - */ |
|
| 74 | + /** |
|
| 75 | + * @var string[] |
|
| 76 | + */ |
|
| 77 | 77 | protected $selected = array(); |
| 78 | 78 | |
| 79 | 79 | public function convert(string $string) : string |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | return str_replace(array_keys($chars), array_values($chars), $string); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Selects a character set to replace. Can be called |
|
| 88 | - * several times to add additional sets to the collection. |
|
| 89 | - * |
|
| 90 | - * @param string $type See the <code>CHAR_XXX</code> constants. |
|
| 91 | - * @return ConvertHelper_HiddenConverter |
|
| 92 | - * |
|
| 93 | - * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
| 94 | - * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
| 95 | - */ |
|
| 86 | + /** |
|
| 87 | + * Selects a character set to replace. Can be called |
|
| 88 | + * several times to add additional sets to the collection. |
|
| 89 | + * |
|
| 90 | + * @param string $type See the <code>CHAR_XXX</code> constants. |
|
| 91 | + * @return ConvertHelper_HiddenConverter |
|
| 92 | + * |
|
| 93 | + * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
| 94 | + * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
| 95 | + */ |
|
| 96 | 96 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
| 97 | 97 | { |
| 98 | 98 | if(!in_array($type, $this->selected)) { |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | return $this; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Resolves the list of characters to make visible. |
|
| 107 | - * |
|
| 108 | - * @return string[] |
|
| 109 | - */ |
|
| 105 | + /** |
|
| 106 | + * Resolves the list of characters to make visible. |
|
| 107 | + * |
|
| 108 | + * @return string[] |
|
| 109 | + */ |
|
| 110 | 110 | protected function resolveSelection() : array |
| 111 | 111 | { |
| 112 | 112 | $selected = $this->selected; |