@@ -189,6 +189,9 @@ |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | + /** |
|
| 193 | + * @param string $value |
|
| 194 | + */ |
|
| 192 | 195 | public function setLanguage($value) { |
| 193 | 196 | if (!empty($value)) |
| 194 | 197 | $this->meta['language'] = strtolower((string)$value); |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | * @brief Removes `_design/` from he document identifier. |
| 64 | 64 | */ |
| 65 | 65 | protected function fixDocId() { |
| 66 | - if (isset($this->meta['_id'])) |
|
| 67 | - $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']); |
|
| 66 | + if (isset($this->meta['_id'])) { |
|
| 67 | + $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']); |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | |
@@ -94,8 +95,9 @@ discard block |
||
| 94 | 95 | */ |
| 95 | 96 | public function resetHandlers() { |
| 96 | 97 | foreach ($this->sections as $name => $value) { |
| 97 | - if (array_key_exists($name, $this->meta)) |
|
| 98 | - unset($this->meta[$name]); |
|
| 98 | + if (array_key_exists($name, $this->meta)) { |
|
| 99 | + unset($this->meta[$name]); |
|
| 100 | + } |
|
| 99 | 101 | } |
| 100 | 102 | } |
| 101 | 103 | |
@@ -108,16 +110,17 @@ discard block |
||
| 108 | 110 | */ |
| 109 | 111 | public function getHandlerAttributes($section, $name = "") { |
| 110 | 112 | if (empty($name)) { // The handler doesn't have a name. |
| 111 | - if (array_key_exists($section, $this->meta)) |
|
| 112 | - return $this->meta[$section]; |
|
| 113 | - else |
|
| 114 | - throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section)); |
|
| 115 | - } |
|
| 116 | - else { // The handler has a name. |
|
| 117 | - if (@array_key_exists($name, $this->meta[$section])) |
|
| 118 | - return $this->meta[$section][$name]; |
|
| 119 | - else |
|
| 120 | - throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section)); |
|
| 113 | + if (array_key_exists($section, $this->meta)) { |
|
| 114 | + return $this->meta[$section]; |
|
| 115 | + } else { |
|
| 116 | + throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section)); |
|
| 117 | + } |
|
| 118 | + } else { // The handler has a name. |
|
| 119 | + if (@array_key_exists($name, $this->meta[$section])) { |
|
| 120 | + return $this->meta[$section][$name]; |
|
| 121 | + } else { |
|
| 122 | + throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section)); |
|
| 123 | + } |
|
| 121 | 124 | } |
| 122 | 125 | } |
| 123 | 126 | |
@@ -133,22 +136,25 @@ discard block |
||
| 133 | 136 | $section = $handler->getSection(); |
| 134 | 137 | |
| 135 | 138 | if (property_exists($handler, "name")) { |
| 136 | - if (!$handler->isConsistent()) |
|
| 137 | - throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name)); |
|
| 138 | - |
|
| 139 | - if (@array_key_exists($handler->name, $this->meta[$section])) |
|
| 140 | - throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name)); |
|
| 141 | - else |
|
| 142 | - $this->meta[$section][$handler->name] = $handler->asArray(); |
|
| 143 | - } |
|
| 144 | - else { |
|
| 145 | - if (!$handler->isConsistent()) |
|
| 146 | - throw new \Exception(sprintf("The '%s' handler is not consistent.", $section)); |
|
| 147 | - |
|
| 148 | - if (array_key_exists($section, $this->meta)) |
|
| 149 | - throw new \Exception(sprintf("The '%s' handler already exists.", $section)); |
|
| 150 | - else |
|
| 151 | - $this->meta[$section] = $handler; |
|
| 139 | + if (!$handler->isConsistent()) { |
|
| 140 | + throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name)); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (@array_key_exists($handler->name, $this->meta[$section])) { |
|
| 144 | + throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name)); |
|
| 145 | + } else { |
|
| 146 | + $this->meta[$section][$handler->name] = $handler->asArray(); |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + if (!$handler->isConsistent()) { |
|
| 150 | + throw new \Exception(sprintf("The '%s' handler is not consistent.", $section)); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (array_key_exists($section, $this->meta)) { |
|
| 154 | + throw new \Exception(sprintf("The '%s' handler already exists.", $section)); |
|
| 155 | + } else { |
|
| 156 | + $this->meta[$section] = $handler; |
|
| 157 | + } |
|
| 152 | 158 | } |
| 153 | 159 | } |
| 154 | 160 | |
@@ -163,16 +169,17 @@ discard block |
||
| 163 | 169 | */ |
| 164 | 170 | public function removeHandler($section, $name = "") { |
| 165 | 171 | if (empty($name)) { // The handler doesn't have a name. |
| 166 | - if (array_key_exists($section, $this->meta)) |
|
| 167 | - unset($this->meta[$section]); |
|
| 168 | - else |
|
| 169 | - throw new \Exception(sprintf("Can't find the '%s' handler.", $section)); |
|
| 170 | - } |
|
| 171 | - else { // The handler has a name. |
|
| 172 | - if (@array_key_exists($name, $this->meta[$section])) |
|
| 173 | - unset($this->meta[$section][$name]); |
|
| 174 | - else |
|
| 175 | - throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name)); |
|
| 172 | + if (array_key_exists($section, $this->meta)) { |
|
| 173 | + unset($this->meta[$section]); |
|
| 174 | + } else { |
|
| 175 | + throw new \Exception(sprintf("Can't find the '%s' handler.", $section)); |
|
| 176 | + } |
|
| 177 | + } else { // The handler has a name. |
|
| 178 | + if (@array_key_exists($name, $this->meta[$section])) { |
|
| 179 | + unset($this->meta[$section][$name]); |
|
| 180 | + } else { |
|
| 181 | + throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name)); |
|
| 182 | + } |
|
| 176 | 183 | } |
| 177 | 184 | } |
| 178 | 185 | |
@@ -190,16 +197,18 @@ discard block |
||
| 190 | 197 | |
| 191 | 198 | |
| 192 | 199 | public function setLanguage($value) { |
| 193 | - if (!empty($value)) |
|
| 194 | - $this->meta['language'] = strtolower((string)$value); |
|
| 195 | - else |
|
| 196 | - throw new \InvalidArgumentException("\$language must be a non-empty string."); |
|
| 200 | + if (!empty($value)) { |
|
| 201 | + $this->meta['language'] = strtolower((string)$value); |
|
| 202 | + } else { |
|
| 203 | + throw new \InvalidArgumentException("\$language must be a non-empty string."); |
|
| 204 | + } |
|
| 197 | 205 | } |
| 198 | 206 | |
| 199 | 207 | |
| 200 | 208 | public function unsetLanguage() { |
| 201 | - if ($this->isMetadataPresent('language')) |
|
| 202 | - unset($this->meta['language']); |
|
| 209 | + if ($this->isMetadataPresent('language')) { |
|
| 210 | + unset($this->meta['language']); |
|
| 211 | + } |
|
| 203 | 212 | } |
| 204 | 213 | |
| 205 | 214 | //! @endcond |
@@ -162,6 +162,11 @@ discard block |
||
| 162 | 162 | /* |
| 163 | 163 | * Public API, convert a UUID from one format to another |
| 164 | 164 | */ |
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param integer $from |
|
| 168 | + * @param integer $to |
|
| 169 | + */ |
|
| 165 | 170 | static public function convert($uuid, $from, $to) { |
| 166 | 171 | $conv = self::$m_convert[$from][$to]; |
| 167 | 172 | if (!isset($conv)) |
@@ -189,6 +194,11 @@ discard block |
||
| 189 | 194 | /* |
| 190 | 195 | * Generate UUID version 3 and 5 (name based) |
| 191 | 196 | */ |
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param string $hash |
|
| 200 | + * @param integer $version |
|
| 201 | + */ |
|
| 192 | 202 | static private function generateName($ns, $node, $hash, $version) { |
| 193 | 203 | $ns_fmt = self::detectFormat($ns); |
| 194 | 204 | $field = self::convert($ns, $ns_fmt, self::FMT_FIELD); |
@@ -131,17 +131,18 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | /* Auto-detect UUID format */ |
| 133 | 133 | static private function detectFormat($src) { |
| 134 | - if (is_string($src)) |
|
| 135 | - return self::FMT_STRING; |
|
| 136 | - else if (is_array($src)) { |
|
| 134 | + if (is_string($src)) { |
|
| 135 | + return self::FMT_STRING; |
|
| 136 | + } else if (is_array($src)) { |
|
| 137 | 137 | $len = count($src); |
| 138 | - if ($len == 1 || ($len % 2) == 0) |
|
| 139 | - return $len; |
|
| 140 | - else |
|
| 141 | - return (-1); |
|
| 138 | + if ($len == 1 || ($len % 2) == 0) { |
|
| 139 | + return $len; |
|
| 140 | + } else { |
|
| 141 | + return (-1); |
|
| 142 | + } |
|
| 143 | + } else { |
|
| 144 | + return self::FMT_BINARY; |
|
| 142 | 145 | } |
| 143 | - else |
|
| 144 | - return self::FMT_BINARY; |
|
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | /* |
@@ -151,8 +152,9 @@ discard block |
||
| 151 | 152 | static public function generate($type, $fmt = self::FMT_BYTE, |
| 152 | 153 | $node = "", $ns = "") { |
| 153 | 154 | $func = self::$m_generate[$type]; |
| 154 | - if (!isset($func)) |
|
| 155 | - return null; |
|
| 155 | + if (!isset($func)) { |
|
| 156 | + return null; |
|
| 157 | + } |
|
| 156 | 158 | $conv = self::$m_convert[self::FMT_FIELD][$fmt]; |
| 157 | 159 | |
| 158 | 160 | $uuid = self::$func($ns, $node); |
@@ -164,8 +166,9 @@ discard block |
||
| 164 | 166 | */ |
| 165 | 167 | static public function convert($uuid, $from, $to) { |
| 166 | 168 | $conv = self::$m_convert[$from][$to]; |
| 167 | - if (!isset($conv)) |
|
| 168 | - return ($uuid); |
|
| 169 | + if (!isset($conv)) { |
|
| 170 | + return ($uuid); |
|
| 171 | + } |
|
| 169 | 172 | |
| 170 | 173 | return (self::$conv($uuid)); |
| 171 | 174 | } |
@@ -181,8 +184,9 @@ discard block |
||
| 181 | 184 | $uuid['time_low'] = mt_rand(0, 0xffff) + (mt_rand(0, 0xffff) << 16); |
| 182 | 185 | $uuid['time_mid'] = mt_rand(0, 0xffff); |
| 183 | 186 | $uuid['clock_seq_low'] = mt_rand(0, 255); |
| 184 | - for ($i = 0; $i < 6; $i++) |
|
| 185 | - $uuid['node'][$i] = mt_rand(0, 255); |
|
| 187 | + for ($i = 0; $i < 6; $i++) { |
|
| 188 | + $uuid['node'][$i] = mt_rand(0, 255); |
|
| 189 | + } |
|
| 186 | 190 | return ($uuid); |
| 187 | 191 | } |
| 188 | 192 | |
@@ -205,8 +209,9 @@ discard block |
||
| 205 | 209 | /* Hash the namespace and node and convert to a byte array */ |
| 206 | 210 | $val = $hash($raw, true); |
| 207 | 211 | $tmp = unpack('C16', $val); |
| 208 | - foreach (array_keys($tmp) as $key) |
|
| 209 | - $byte[$key - 1] = $tmp[$key]; |
|
| 212 | + foreach (array_keys($tmp) as $key) { |
|
| 213 | + $byte[$key - 1] = $tmp[$key]; |
|
| 214 | + } |
|
| 210 | 215 | |
| 211 | 216 | /* Convert byte array to a field array */ |
| 212 | 217 | $field = self::conv_byte2field($byte); |
@@ -264,8 +269,9 @@ discard block |
||
| 264 | 269 | * Node should be set to the 48-bit IEEE node identifier, but |
| 265 | 270 | * we leave it for the user to supply the node. |
| 266 | 271 | */ |
| 267 | - for ($i = 0; $i < 6; $i++) |
|
| 268 | - $uuid['node'][$i] = ord(substr($node, $i, 1)); |
|
| 272 | + for ($i = 0; $i < 6; $i++) { |
|
| 273 | + $uuid['node'][$i] = ord(substr($node, $i, 1)); |
|
| 274 | + } |
|
| 269 | 275 | |
| 270 | 276 | return ($uuid); |
| 271 | 277 | } |
@@ -283,8 +289,9 @@ discard block |
||
| 283 | 289 | $uuid[8] = $src['clock_seq_hi']; |
| 284 | 290 | $uuid[9] = $src['clock_seq_low']; |
| 285 | 291 | |
| 286 | - for ($i = 0; $i < 6; $i++) |
|
| 287 | - $uuid[10+$i] = $src['node'][$i]; |
|
| 292 | + for ($i = 0; $i < 6; $i++) { |
|
| 293 | + $uuid[10+$i] = $src['node'][$i]; |
|
| 294 | + } |
|
| 288 | 295 | |
| 289 | 296 | return ($uuid); |
| 290 | 297 | } |
@@ -313,8 +320,9 @@ discard block |
||
| 313 | 320 | $field['clock_seq_hi'] = $uuid[8]; |
| 314 | 321 | $field['clock_seq_low'] = $uuid[9]; |
| 315 | 322 | |
| 316 | - for ($i = 0; $i < 6; $i++) |
|
| 317 | - $field['node'][$i] = $uuid[10+$i]; |
|
| 323 | + for ($i = 0; $i < 6; $i++) { |
|
| 324 | + $field['node'][$i] = $uuid[10+$i]; |
|
| 325 | + } |
|
| 318 | 326 | return ($field); |
| 319 | 327 | } |
| 320 | 328 | |
@@ -338,8 +346,9 @@ discard block |
||
| 338 | 346 | $field['time_hi'] = ($parts[2]); |
| 339 | 347 | $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8; |
| 340 | 348 | $field['clock_seq_low'] = $parts[3] & 0x00ff; |
| 341 | - for ($i = 0; $i < 6; $i++) |
|
| 342 | - $field['node'][$i] = $parts[4+$i]; |
|
| 349 | + for ($i = 0; $i < 6; $i++) { |
|
| 350 | + $field['node'][$i] = $parts[4+$i]; |
|
| 351 | + } |
|
| 343 | 352 | |
| 344 | 353 | return ($field); |
| 345 | 354 | } |
@@ -266,6 +266,7 @@ discard block |
||
| 266 | 266 | * @param[in] string $path The absolute path of the request. |
| 267 | 267 | * @param[in] string $queryParams (optional) Associative array of query parameters. |
| 268 | 268 | * @param[in] string $headerFields (optional) Associative array of header fields. |
| 269 | + * @param string $path |
|
| 269 | 270 | */ |
| 270 | 271 | public function __construct($method, $path, array $queryParams = NULL, array $headerFields = NULL) { |
| 271 | 272 | parent::__construct(); |
@@ -419,6 +420,8 @@ discard block |
||
| 419 | 420 | * @brief This helper forces request to use the Authorization Basic mode. |
| 420 | 421 | * @param[in] string $userName User name. |
| 421 | 422 | * @param[in] string $password Password. |
| 423 | + * @param string $userName |
|
| 424 | + * @param string $password |
|
| 422 | 425 | */ |
| 423 | 426 | public function setBasicAuth($userName, $password) { |
| 424 | 427 | $this->setHeaderField(self::AUTHORIZATION_HF, "Basic ".base64_encode("$userName:$password")); |
@@ -281,11 +281,13 @@ discard block |
||
| 281 | 281 | $this->setMethod($method); |
| 282 | 282 | $this->setPath($path); |
| 283 | 283 | |
| 284 | - if (isset($queryParams)) |
|
| 285 | - $this->setMultipleQueryParamsAtOnce($queryParams); |
|
| 284 | + if (isset($queryParams)) { |
|
| 285 | + $this->setMultipleQueryParamsAtOnce($queryParams); |
|
| 286 | + } |
|
| 286 | 287 | |
| 287 | - if (isset($headerFields)) |
|
| 288 | - $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
| 288 | + if (isset($headerFields)) { |
|
| 289 | + $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
| 290 | + } |
|
| 289 | 291 | } |
| 290 | 292 | |
| 291 | 293 | |
@@ -318,10 +320,11 @@ discard block |
||
| 318 | 320 | * @param[in] string $method The HTTP method for the request. You should use one of the public constants, like GET_METHOD. |
| 319 | 321 | */ |
| 320 | 322 | public function setMethod($method) { |
| 321 | - if (array_key_exists($method, self::$supportedMethods)) |
|
| 322 | - $this->method = $method; |
|
| 323 | - else |
|
| 324 | - throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
| 323 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
| 324 | + $this->method = $method; |
|
| 325 | + } else { |
|
| 326 | + throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
| 327 | + } |
|
| 325 | 328 | } |
| 326 | 329 | |
| 327 | 330 | |
@@ -330,10 +333,11 @@ discard block |
||
| 330 | 333 | * @param[in] string $method The HTTP custom method. |
| 331 | 334 | */ |
| 332 | 335 | public static function addCustomMethod($method) { |
| 333 | - if (array_key_exists($method, self::$supportedMethods)) |
|
| 334 | - throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
| 335 | - else |
|
| 336 | - self::$supportedMethods[] = $method; |
|
| 336 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
| 337 | + throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
| 338 | + } else { |
|
| 339 | + self::$supportedMethods[] = $method; |
|
| 340 | + } |
|
| 337 | 341 | } |
| 338 | 342 | |
| 339 | 343 | |
@@ -351,10 +355,11 @@ discard block |
||
| 351 | 355 | * @param[in] string $path The absolute path of the request. |
| 352 | 356 | */ |
| 353 | 357 | public function setPath($path) { |
| 354 | - if (is_string($path)) |
|
| 355 | - $this->path = addslashes($path); |
|
| 356 | - else |
|
| 357 | - throw new \InvalidArgumentException("\$path must be a string."); |
|
| 358 | + if (is_string($path)) { |
|
| 359 | + $this->path = addslashes($path); |
|
| 360 | + } else { |
|
| 361 | + throw new \InvalidArgumentException("\$path must be a string."); |
|
| 362 | + } |
|
| 358 | 363 | } |
| 359 | 364 | |
| 360 | 365 | |
@@ -364,11 +369,12 @@ discard block |
||
| 364 | 369 | * @param[in] string $value Parameter value. |
| 365 | 370 | */ |
| 366 | 371 | public function setQueryParam($name, $value) { |
| 367 | - if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) |
|
| 368 | - $this->queryParams[$name] = $value; |
|
| 369 | - else |
|
| 370 | - throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
| 372 | + if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) { |
|
| 373 | + $this->queryParams[$name] = $value; |
|
| 374 | + } else { |
|
| 375 | + throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
| 371 | 376 | letters, numbers, or underscores."); |
| 377 | + } |
|
| 372 | 378 | } |
| 373 | 379 | |
| 374 | 380 | |
@@ -377,11 +383,12 @@ discard block |
||
| 377 | 383 | * @param[in] array $params An associative array of parameters. |
| 378 | 384 | */ |
| 379 | 385 | public function setMultipleQueryParamsAtOnce(array $params) { |
| 380 | - if (Helper\ArrayHelper::isAssociative($params)) |
|
| 381 | - foreach ($params as $name => $value) |
|
| 386 | + if (Helper\ArrayHelper::isAssociative($params)) { |
|
| 387 | + foreach ($params as $name => $value) |
|
| 382 | 388 | $this->setQueryParam($name, $value); |
| 383 | - else |
|
| 384 | - throw new \InvalidArgumentException("\$params must be an associative array."); |
|
| 389 | + } else { |
|
| 390 | + throw new \InvalidArgumentException("\$params must be an associative array."); |
|
| 391 | + } |
|
| 385 | 392 | } |
| 386 | 393 | |
| 387 | 394 | |
@@ -390,11 +397,12 @@ discard block |
||
| 390 | 397 | * @retval string |
| 391 | 398 | */ |
| 392 | 399 | public function getQueryString() { |
| 393 | - if (empty($this->queryParams)) |
|
| 394 | - return ""; |
|
| 395 | - else |
|
| 396 | - // Encoding is based on RFC 3986. |
|
| 400 | + if (empty($this->queryParams)) { |
|
| 401 | + return ""; |
|
| 402 | + } else { |
|
| 403 | + // Encoding is based on RFC 3986. |
|
| 397 | 404 | return "?".http_build_query($this->queryParams, NULL, "&", PHP_QUERY_RFC3986); |
| 405 | + } |
|
| 398 | 406 | } |
| 399 | 407 | |
| 400 | 408 | |
@@ -45,10 +45,11 @@ |
||
| 45 | 45 | * @retval string|bool The codec name or `false` if the attachment is not compressed. |
| 46 | 46 | */ |
| 47 | 47 | public function getContentEncoding() { |
| 48 | - if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) |
|
| 49 | - return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 50 | - else |
|
| 51 | - return FALSE; |
|
| 48 | + if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) { |
|
| 49 | + return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 50 | + } else { |
|
| 51 | + return FALSE; |
|
| 52 | + } |
|
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | |
@@ -82,9 +82,9 @@ |
||
| 82 | 82 | $this->purgeSeq = $info['purge_seq']; |
| 83 | 83 | $this->compactRunning = $info['compact_running']; |
| 84 | 84 | $this->committedUpdateSeq = $info['committed_update_seq']; |
| 85 | + } else { |
|
| 86 | + throw new \Exception("\$info must be an associative array."); |
|
| 85 | 87 | } |
| 86 | - else |
|
| 87 | - throw new \Exception("\$info must be an associative array."); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -25,8 +25,9 @@ |
||
| 25 | 25 | * @brief Removes `_local/` from he document identifier. |
| 26 | 26 | */ |
| 27 | 27 | protected function fixDocId() { |
| 28 | - if (isset($this->meta['_id'])) |
|
| 29 | - $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']); |
|
| 28 | + if (isset($this->meta['_id'])) { |
|
| 29 | + $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']); |
|
| 30 | + } |
|
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | |
@@ -59,10 +59,11 @@ |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | public function setId($value) { |
| 62 | - if (!empty($value)) |
|
| 63 | - $this->id = (string)$value; |
|
| 64 | - else |
|
| 65 | - throw new \Exception("\$id must be a non-empty string."); |
|
| 62 | + if (!empty($value)) { |
|
| 63 | + $this->id = (string)$value; |
|
| 64 | + } else { |
|
| 65 | + throw new \Exception("\$id must be a non-empty string."); |
|
| 66 | + } |
|
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | $instance = new self(); |
| 42 | 42 | |
| 43 | 43 | if (file_exists($fileName)) { |
| 44 | - if (is_dir($fileName)) |
|
| 45 | - throw new \Exception("The file $fileName is a directory."); |
|
| 44 | + if (is_dir($fileName)) { |
|
| 45 | + throw new \Exception("The file $fileName is a directory."); |
|
| 46 | + } |
|
| 46 | 47 | |
| 47 | 48 | $instance->name = basename($fileName); |
| 48 | 49 | |
@@ -58,14 +59,15 @@ discard block |
||
| 58 | 59 | finfo_close($finfo); |
| 59 | 60 | fclose($fd); |
| 60 | 61 | |
| 61 | - if ($instance->data === FALSE) |
|
| 62 | - throw new \Exception("Error reading the file $fileName."); |
|
| 62 | + if ($instance->data === FALSE) { |
|
| 63 | + throw new \Exception("Error reading the file $fileName."); |
|
| 64 | + } |
|
| 65 | + } else { |
|
| 66 | + throw new \Exception("Cannot open the file $fileName."); |
|
| 63 | 67 | } |
| 64 | - else |
|
| 65 | - throw new \Exception("Cannot open the file $fileName."); |
|
| 68 | + } else { |
|
| 69 | + throw new \Exception("The file $fileName doesn't exist."); |
|
| 66 | 70 | } |
| 67 | - else |
|
| 68 | - throw new \Exception("The file $fileName doesn't exist."); |
|
| 69 | 71 | |
| 70 | 72 | return $instance; |
| 71 | 73 | } |
@@ -101,11 +103,12 @@ discard block |
||
| 101 | 103 | $bytes = fwrite($fd, $this->data); |
| 102 | 104 | fclose($fd); |
| 103 | 105 | |
| 104 | - if ($bytes === FALSE) |
|
| 105 | - throw new \Exception("Error writing the file `$this->name`."); |
|
| 106 | + if ($bytes === FALSE) { |
|
| 107 | + throw new \Exception("Error writing the file `$this->name`."); |
|
| 108 | + } |
|
| 109 | + } else { |
|
| 110 | + throw new \Exception("Cannot create the file `$this->name`."); |
|
| 106 | 111 | } |
| 107 | - else |
|
| 108 | - throw new \Exception("Cannot create the file `$this->name`."); |
|
| 109 | 112 | } |
| 110 | 113 | |
| 111 | 114 | |
@@ -54,8 +54,9 @@ discard block |
||
| 54 | 54 | public function getAttachments() { |
| 55 | 55 | $attachments = []; |
| 56 | 56 | |
| 57 | - foreach ($this->meta[self::ATTACHMENTS] as $attachment) |
|
| 58 | - $attachments[] = Attachment::fromArray($attachment); |
|
| 57 | + foreach ($this->meta[self::ATTACHMENTS] as $attachment) { |
|
| 58 | + $attachments[] = Attachment::fromArray($attachment); |
|
| 59 | + } |
|
| 59 | 60 | |
| 60 | 61 | return $attachments; |
| 61 | 62 | } |
@@ -75,13 +76,15 @@ discard block |
||
| 75 | 76 | * @todo To be documented. |
| 76 | 77 | */ |
| 77 | 78 | public function removeAttachment($name) { |
| 78 | - if ($this->isMetadataPresent(self::ATTACHMENTS)) |
|
| 79 | - if (array_key_exists($name, $this->meta[self::ATTACHMENTS])) |
|
| 79 | + if ($this->isMetadataPresent(self::ATTACHMENTS)) { |
|
| 80 | + if (array_key_exists($name, $this->meta[self::ATTACHMENTS])) |
|
| 80 | 81 | unset($this->meta[self::ATTACHMENTS][$name]); |
| 81 | - else |
|
| 82 | - throw new \Exception("Can't find `$name` attachment in the document."); |
|
| 83 | - else |
|
| 84 | - throw new \Exception("The document doesn't have any attachment."); |
|
| 82 | + } else { |
|
| 83 | + throw new \Exception("Can't find `$name` attachment in the document."); |
|
| 84 | + } |
|
| 85 | + else { |
|
| 86 | + throw new \Exception("The document doesn't have any attachment."); |
|
| 87 | + } |
|
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | |