| @@ -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); | 
| @@ -67,29 +67,29 @@ discard block | ||
| 67 | 67 | */ | 
| 68 | 68 |  class UUID { | 
| 69 | 69 | /* UUID versions */ | 
| 70 | - const UUID_TIME = 1; /* Time based UUID */ | |
| 71 | - const UUID_NAME_MD5 = 3; /* Name based (MD5) UUID */ | |
| 72 | - const UUID_RANDOM = 4; /* Random UUID */ | |
| 73 | - const UUID_NAME_SHA1 = 5; /* Name based (SHA1) UUID */ | |
| 70 | + const UUID_TIME = 1; /* Time based UUID */ | |
| 71 | + const UUID_NAME_MD5 = 3; /* Name based (MD5) UUID */ | |
| 72 | + const UUID_RANDOM = 4; /* Random UUID */ | |
| 73 | + const UUID_NAME_SHA1 = 5; /* Name based (SHA1) UUID */ | |
| 74 | 74 | |
| 75 | 75 | /* UUID formats */ | 
| 76 | 76 | const FMT_FIELD = 100; | 
| 77 | 77 | const FMT_STRING = 101; | 
| 78 | 78 | const FMT_BINARY = 102; | 
| 79 | - const FMT_QWORD = 1; /* Quad-word, 128-bit (not impl.) */ | |
| 80 | - const FMT_DWORD = 2; /* Double-word, 64-bit (not impl.) */ | |
| 81 | - const FMT_WORD = 4; /* Word, 32-bit (not impl.) */ | |
| 82 | - const FMT_SHORT = 8; /* Short (not impl.) */ | |
| 83 | - const FMT_BYTE = 16; /* Byte */ | |
| 84 | - const FMT_DEFAULT = 16; | |
| 79 | + const FMT_QWORD = 1; /* Quad-word, 128-bit (not impl.) */ | |
| 80 | + const FMT_DWORD = 2; /* Double-word, 64-bit (not impl.) */ | |
| 81 | + const FMT_WORD = 4; /* Word, 32-bit (not impl.) */ | |
| 82 | + const FMT_SHORT = 8; /* Short (not impl.) */ | |
| 83 | + const FMT_BYTE = 16; /* Byte */ | |
| 84 | + const FMT_DEFAULT = 16; | |
| 85 | 85 | |
| 86 | 86 | /* Field UUID representation */ | 
| 87 | 87 | static private $m_uuid_field = array( | 
| 88 | - 'time_low' => 0, /* 32-bit */ | |
| 89 | - 'time_mid' => 0, /* 16-bit */ | |
| 90 | - 'time_hi' => 0, /* 16-bit */ | |
| 91 | - 'clock_seq_hi' => 0, /* 8-bit */ | |
| 92 | - 'clock_seq_low' => 0, /* 8-bit */ | |
| 88 | + 'time_low' => 0, /* 32-bit */ | |
| 89 | + 'time_mid' => 0, /* 16-bit */ | |
| 90 | + 'time_hi' => 0, /* 16-bit */ | |
| 91 | + 'clock_seq_hi' => 0, /* 8-bit */ | |
| 92 | + 'clock_seq_low' => 0, /* 8-bit */ | |
| 93 | 93 | 'node' => array() /* 48-bit */ | 
| 94 | 94 | ); | 
| 95 | 95 | |
| @@ -284,7 +284,7 @@ discard block | ||
| 284 | 284 | $uuid[9] = $src['clock_seq_low']; | 
| 285 | 285 | |
| 286 | 286 | for ($i = 0; $i < 6; $i++) | 
| 287 | - $uuid[10+$i] = $src['node'][$i]; | |
| 287 | + $uuid[10 + $i] = $src['node'][$i]; | |
| 288 | 288 | |
| 289 | 289 | return ($uuid); | 
| 290 | 290 | } | 
| @@ -314,7 +314,7 @@ discard block | ||
| 314 | 314 | $field['clock_seq_low'] = $uuid[9]; | 
| 315 | 315 | |
| 316 | 316 | for ($i = 0; $i < 6; $i++) | 
| 317 | - $field['node'][$i] = $uuid[10+$i]; | |
| 317 | + $field['node'][$i] = $uuid[10 + $i]; | |
| 318 | 318 | return ($field); | 
| 319 | 319 | } | 
| 320 | 320 | |
| @@ -339,7 +339,7 @@ discard block | ||
| 339 | 339 | $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8; | 
| 340 | 340 | $field['clock_seq_low'] = $parts[3] & 0x00ff; | 
| 341 | 341 | for ($i = 0; $i < 6; $i++) | 
| 342 | - $field['node'][$i] = $parts[4+$i]; | |
| 342 | + $field['node'][$i] = $parts[4 + $i]; | |
| 343 | 343 | |
| 344 | 344 | return ($field); | 
| 345 | 345 | } | 
| @@ -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 | } | 
| @@ -100,8 +100,8 @@ | ||
| 100 | 100 | $buffer .= "File Opened Since: ".sprintf($since, $time['days'], $time['hours'], $time['minutes'], $time['seconds']).PHP_EOL; | 
| 101 | 101 | } | 
| 102 | 102 | |
| 103 | - $buffer .= "Disk Size: ".round($this->diskSize/(1024*1024*1024), 3)." GB".PHP_EOL; | |
| 104 | - $buffer .= "Data Size: ".round($this->dataSize/(1024*1024*1024), 3)." GB".PHP_EOL; | |
| 103 | + $buffer .= "Disk Size: ".round($this->diskSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL; | |
| 104 | + $buffer .= "Data Size: ".round($this->dataSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL; | |
| 105 | 105 | $buffer .= "Disk Format Version: ".$this->diskFormatVersion.PHP_EOL; | 
| 106 | 106 | |
| 107 | 107 | $compactRunning = ($this->compactRunning) ? 'active' : 'inactive'; | 
| @@ -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 | |
| @@ -908,7 +908,7 @@ | ||
| 908 | 908 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate | 
| 909 | 909 | */ | 
| 910 | 910 | public function startReplication($sourceDbUrl, $targetDbUrl, $proxy = NULL, $createTargetDb = TRUE, | 
| 911 | -                                     $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) { | |
| 911 | +                                      $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) { | |
| 912 | 912 | // Sets source and target databases. | 
| 913 | 913 | if (is_string($sourceDbUrl) && !empty($sourceDbUrl) && | 
| 914 | 914 |        is_string($targetDbUrl) && !empty($targetDbUrl)) { | 
| @@ -35,8 +35,8 @@ discard block | ||
| 35 | 35 |    //!@{ | 
| 36 | 36 | |
| 37 | 37 | const STD_DOC_PATH = ""; //!< Path for standard documents. | 
| 38 | - const LOCAL_DOC_PATH = "_local/"; //!< Path for local documents. | |
| 39 | - const DESIGN_DOC_PATH = "_design/"; //!< Path for design documents. | |
| 38 | + const LOCAL_DOC_PATH = "_local/"; //!< Path for local documents. | |
| 39 | + const DESIGN_DOC_PATH = "_design/"; //!< Path for design documents. | |
| 40 | 40 | |
| 41 | 41 | //!@} | 
| 42 | 42 | |
| @@ -662,7 +662,7 @@ discard block | ||
| 662 | 662 | * @see http://docs.couchdb.org/en/latest/api/database/compact.html#db-view-cleanup | 
| 663 | 663 | */ | 
| 664 | 664 |    public function cleanupViews($dbName) { | 
| 665 | - $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_view_cleanup"); | |
| 665 | + $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_view_cleanup"); | |
| 666 | 666 | |
| 667 | 667 | // A POST method requires Content-Type header. | 
| 668 | 668 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); | 
| @@ -297,7 +297,7 @@ discard block | ||
| 297 | 297 | |
| 298 | 298 | /** | 
| 299 | 299 | * @brief Returns a list of all database events in the CouchDB instance. | 
| 300 | - * @param DbUpdatesFeedOpts $opts Additional options. | |
| 300 | + * @param Opt\DbUpdatesFeedOpts $opts Additional options. | |
| 301 | 301 | * @return Response | 
| 302 | 302 | * @attention Requires admin privileges. | 
| 303 | 303 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#db-updates | 
| @@ -577,7 +577,7 @@ discard block | ||
| 577 | 577 | * @brief Obtains a list of the changes made to the database. This can be used to monitor for update and modifications | 
| 578 | 578 | * to the database for post processing or synchronization. | 
| 579 | 579 | * @param string $name The database name. | 
| 580 | - * @param ChangesFeedOpts $opts Additional options. | |
| 580 | + * @param Opt\ChangesFeedOpts $opts Additional options. | |
| 581 | 581 | * @return Response | 
| 582 | 582 | * @see http://docs.couchdb.org/en/latest/api/database/changes.html | 
| 583 | 583 | */ | 
| @@ -708,7 +708,7 @@ discard block | ||
| 708 | 708 | /** | 
| 709 | 709 | * @brief Returns the special security object for the database. | 
| 710 | 710 | * @param string $dbName The database name. | 
| 711 | - * @return string A JSON object. | |
| 711 | + * @return Response A JSON object. | |
| 712 | 712 | * @see http://docs.couchdb.org/en/latest/api/database/security.html#get--db-_security | 
| 713 | 713 | */ | 
| 714 | 714 |    public function getSecurityObj($dbName) { | 
| @@ -762,7 +762,7 @@ discard block | ||
| 762 | 762 | * permanent continuous replications that survive a server restart without you having to do anything. | 
| 763 | 763 | * @param string|array $filter (optional) Name of a filter function that can choose which revisions get replicated. | 
| 764 | 764 | * You can also provide an array of document identifiers; if given, only these documents will be replicated. | 
| 765 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 765 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 766 | 766 | * docs, etc. | 
| 767 | 767 | * @return Response | 
| 768 | 768 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate | 
| @@ -866,7 +866,7 @@ discard block | ||
| 866 | 866 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned | 
| 867 | 867 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called | 
| 868 | 868 | * multi-document-fetch feature. | 
| 869 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 869 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 870 | 870 | * docs, etc. | 
| 871 | 871 | * @param ChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. | 
| 872 | 872 | * @return Result::QueryResult The result of the query. | 
| @@ -898,7 +898,7 @@ discard block | ||
| 898 | 898 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned | 
| 899 | 899 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called | 
| 900 | 900 | * multi-document-fetch feature. | 
| 901 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 901 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 902 | 902 | * docs, etc. | 
| 903 | 903 | * @param IChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. | 
| 904 | 904 | * @return Result::QueryResult The result of the query. | 
| @@ -950,7 +950,7 @@ discard block | ||
| 950 | 950 | * @param array $keys (optional) Used to retrieve just the view rows matching that set of keys. Rows are returned | 
| 951 | 951 | * in the order of the specified keys. Combining this feature with Opt\ViewQueryOpts.includeDocs() results in the so-called | 
| 952 | 952 | * multi-document-fetch feature. | 
| 953 | - * @param ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 953 | + * @param Opt\ViewQueryOpts $opts (optional) Query options to get additional information, grouping results, include | |
| 954 | 954 | * docs, etc. | 
| 955 | 955 | * @param string $language The language used to implement the map and reduce functions. | 
| 956 | 956 | * @param IChunkHook $chunkHook (optional) A class instance that implements the IChunkHook interface. | 
| @@ -1090,7 +1090,7 @@ discard block | ||
| 1090 | 1090 | * @param string $docId The document's identifier. | 
| 1091 | 1091 | * @param string $path The document's path. | 
| 1092 | 1092 | * @param string $rev (optional) The document's revision. | 
| 1093 | - * @param DocOpts $opts Query options to get additional document information, like conflicts, attachments, etc. | |
| 1093 | + * @param Opt\DocOpts $opts Query options to get additional document information, like conflicts, attachments, etc. | |
| 1094 | 1094 | * @return object|Response An instance of Doc, LocalDoc, DesignDoc or any subclass of Doc. | 
| 1095 | 1095 | * @see http://docs.couchdb.org/en/latest/api/document/common.html#get--db-docid | 
| 1096 | 1096 | */ | 
| @@ -1145,7 +1145,7 @@ discard block | ||
| 1145 | 1145 | * using PUT instead we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. | 
| 1146 | 1146 | * This is an internal detail. You have only to know that CouchDB can generate the document id for you. | 
| 1147 | 1147 | * @param string $dbName The database name. | 
| 1148 | - * @param Doc $doc The document you want insert or update. | |
| 1148 | + * @param Doc\IDoc $doc The document you want insert or update. | |
| 1149 | 1149 | * @param bool $batchMode (optional) You can write documents to the database at a higher rate by using the batch | 
| 1150 | 1150 | * option. This collects document writes together in memory (on a user-by-user basis) before they are committed to | 
| 1151 | 1151 | * disk. This increases the risk of the documents not being stored in the event of a failure, since the documents are | 
| @@ -1334,7 +1334,7 @@ discard block | ||
| 1334 | 1334 | * @param string $docId The document's identifier. | 
| 1335 | 1335 | * @param string $path The document's path. | 
| 1336 | 1336 | * @param string $rev (optional) The document's revision. | 
| 1337 | - * @return string The document's revision. | |
| 1337 | + * @return Response The document's revision. | |
| 1338 | 1338 | * @see http://docs.couchdb.org/en/latest/api/document/attachments.html#db-doc-attachment | 
| 1339 | 1339 | */ | 
| 1340 | 1340 |    public function getAttachmentInfo($dbName, $fileName, $path, $docId, $rev = NULL) { | 
| @@ -108,10 +108,13 @@ discard block | ||
| 108 | 108 |        foreach ($keys as $key) { | 
| 109 | 109 | $hash = md5(json_encode($key)); | 
| 110 | 110 | |
| 111 | - if (isset($matches[$hash])) // Match found. | |
| 111 | +        if (isset($matches[$hash])) { | |
| 112 | + // Match found. | |
| 112 | 113 | $allRows[] = $matches[$hash]; | 
| 113 | - else // No match found. | |
| 114 | +        } else { | |
| 115 | + // No match found. | |
| 114 | 116 | $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL]; | 
| 117 | + } | |
| 115 | 118 | } | 
| 116 | 119 | |
| 117 | 120 | // Overrides the response, replacing rows. | 
| @@ -174,15 +177,18 @@ discard block | ||
| 174 | 177 | * @param bool $excludeLocal Document path. | 
| 175 | 178 | */ | 
| 176 | 179 |    public function validateDocPath($path, $excludeLocal = FALSE) { | 
| 177 | - if (empty($path)) // STD_DOC_PATH | |
| 180 | +    if (empty($path)) { | |
| 181 | + // STD_DOC_PATH | |
| 178 | 182 | return; | 
| 183 | + } | |
| 179 | 184 | |
| 180 | - if ($path == self::DESIGN_DOC_PATH) | |
| 181 | - return; | |
| 182 | - elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) | |
| 183 | -      throw new \InvalidArgumentException("Local document doesn't have attachments."); | |
| 184 | - else | |
| 185 | -      throw new \InvalidArgumentException("Invalid document path."); | |
| 185 | +    if ($path == self::DESIGN_DOC_PATH) { | |
| 186 | + return; | |
| 187 | +    } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) { | |
| 188 | +          throw new \InvalidArgumentException("Local document doesn't have attachments."); | |
| 189 | +    } else { | |
| 190 | +          throw new \InvalidArgumentException("Invalid document path."); | |
| 191 | + } | |
| 186 | 192 | } | 
| 187 | 193 | |
| 188 | 194 | |
| @@ -193,10 +199,11 @@ discard block | ||
| 193 | 199 | * @param string $docId Document id. | 
| 194 | 200 | */ | 
| 195 | 201 |    public function validateAndEncodeDocId(&$docId) { | 
| 196 | - if (!empty($docId)) | |
| 197 | - $docId = rawurlencode($docId); | |
| 198 | - else | |
| 199 | -      throw new \InvalidArgumentException("\$docId must be a non-empty string."); | |
| 202 | +    if (!empty($docId)) { | |
| 203 | + $docId = rawurlencode($docId); | |
| 204 | +    } else { | |
| 205 | +          throw new \InvalidArgumentException("\$docId must be a non-empty string."); | |
| 206 | + } | |
| 200 | 207 | } | 
| 201 | 208 | |
| 202 | 209 | //!@} | 
| @@ -228,10 +235,10 @@ discard block | ||
| 228 | 235 | // before the client has received the entire response. To avoid problems, we trap the exception and we go on. | 
| 229 | 236 |      try { | 
| 230 | 237 | $this->send($request); | 
| 231 | - } | |
| 232 | -    catch (\Exception $e) { | |
| 233 | - if ($e->getCode() > 0) | |
| 234 | - throw $e; | |
| 238 | +    } catch (\Exception $e) { | |
| 239 | +      if ($e->getCode() > 0) { | |
| 240 | + throw $e; | |
| 241 | + } | |
| 235 | 242 | } | 
| 236 | 243 | } | 
| 237 | 244 | |
| @@ -268,10 +275,11 @@ discard block | ||
| 268 | 275 |    public function getFavicon() { | 
| 269 | 276 | $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico")); | 
| 270 | 277 | |
| 271 | - if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") | |
| 272 | - return $response->getBody(); | |
| 273 | - else | |
| 274 | -      throw new \InvalidArgumentException("Content-Type must be image/x-icon."); | |
| 278 | +    if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") { | |
| 279 | + return $response->getBody(); | |
| 280 | +    } else { | |
| 281 | +          throw new \InvalidArgumentException("Content-Type must be image/x-icon."); | |
| 282 | + } | |
| 275 | 283 | } | 
| 276 | 284 | |
| 277 | 285 | |
| @@ -305,8 +313,9 @@ discard block | ||
| 305 | 313 |    public function getDbUpdates(Opt\DbUpdatesFeedOpts $opts = NULL) { | 
| 306 | 314 | $request = new Request(Request::GET_METHOD, "/_db_updates"); | 
| 307 | 315 | |
| 308 | - if (isset($opts)) | |
| 309 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 316 | +    if (isset($opts)) { | |
| 317 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 318 | + } | |
| 310 | 319 | |
| 311 | 320 | return $this->send($request)->getBodyAsArray(); | 
| 312 | 321 | } | 
| @@ -335,9 +344,9 @@ discard block | ||
| 335 | 344 | $request = new Request(Request::GET_METHOD, "/_log"); | 
| 336 | 345 |        $request->setQueryParam("bytes", $bytes); | 
| 337 | 346 | return $this->send($request)->getBody(); | 
| 347 | +    } else { | |
| 348 | +          throw new \InvalidArgumentException("\$bytes must be a positive integer."); | |
| 338 | 349 | } | 
| 339 | - else | |
| 340 | -      throw new \InvalidArgumentException("\$bytes must be a positive integer."); | |
| 341 | 350 | } | 
| 342 | 351 | |
| 343 | 352 | |
| @@ -354,13 +363,15 @@ discard block | ||
| 354 | 363 | |
| 355 | 364 | $response = $this->send($request); | 
| 356 | 365 | |
| 357 | - if ($count == 1) // We don't need to use === operator because, just above, we made a type checking. | |
| 366 | +      if ($count == 1) { | |
| 367 | + // We don't need to use === operator because, just above, we made a type checking. | |
| 358 | 368 | return $response->getBodyAsArray()['uuids'][0]; | 
| 359 | - else | |
| 360 | - return $response->getBodyAsArray()['uuids']; | |
| 369 | +      } else { | |
| 370 | + return $response->getBodyAsArray()['uuids']; | |
| 371 | + } | |
| 372 | +    } else { | |
| 373 | +          throw new \InvalidArgumentException("\$count must be a positive integer."); | |
| 361 | 374 | } | 
| 362 | - else | |
| 363 | -      throw new \InvalidArgumentException("\$count must be a positive integer."); | |
| 364 | 375 | } | 
| 365 | 376 | |
| 366 | 377 | //!@} | 
| @@ -384,8 +395,9 @@ discard block | ||
| 384 | 395 |      if (!empty($section)) { | 
| 385 | 396 | $path .= "/".$section; | 
| 386 | 397 | |
| 387 | - if (!empty($key)) | |
| 388 | - $path .= "/".$key; | |
| 398 | +      if (!empty($key)) { | |
| 399 | + $path .= "/".$key; | |
| 400 | + } | |
| 389 | 401 | } | 
| 390 | 402 | |
| 391 | 403 | return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray(); | 
| @@ -400,14 +412,17 @@ discard block | ||
| 400 | 412 | * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key | 
| 401 | 413 | */ | 
| 402 | 414 |    public function setConfigKey($section, $key, $value) { | 
| 403 | - if (!is_string($section) or empty($section)) | |
| 404 | -      throw new \InvalidArgumentException("\$section must be a not empty string."); | |
| 415 | +    if (!is_string($section) or empty($section)) { | |
| 416 | +          throw new \InvalidArgumentException("\$section must be a not empty string."); | |
| 417 | + } | |
| 405 | 418 | |
| 406 | - if (!is_string($key) or empty($key)) | |
| 407 | -      throw new \InvalidArgumentException("\$key must be a not empty string."); | |
| 419 | +    if (!is_string($key) or empty($key)) { | |
| 420 | +          throw new \InvalidArgumentException("\$key must be a not empty string."); | |
| 421 | + } | |
| 408 | 422 | |
| 409 | - if (is_null($value)) | |
| 410 | -      throw new \InvalidArgumentException("\$value cannot be null."); | |
| 423 | +    if (is_null($value)) { | |
| 424 | +          throw new \InvalidArgumentException("\$value cannot be null."); | |
| 425 | + } | |
| 411 | 426 | |
| 412 | 427 | $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key); | 
| 413 | 428 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); | 
| @@ -423,11 +438,13 @@ discard block | ||
| 423 | 438 | * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key | 
| 424 | 439 | */ | 
| 425 | 440 |    public function deleteConfigKey($section, $key) { | 
| 426 | - if (!is_string($section) or empty($section)) | |
| 427 | -      throw new \InvalidArgumentException("\$section must be a not empty string."); | |
| 441 | +    if (!is_string($section) or empty($section)) { | |
| 442 | +          throw new \InvalidArgumentException("\$section must be a not empty string."); | |
| 443 | + } | |
| 428 | 444 | |
| 429 | - if (!is_string($key) or empty($key)) | |
| 430 | -      throw new \InvalidArgumentException("\$key must be a not empty string."); | |
| 445 | +    if (!is_string($key) or empty($key)) { | |
| 446 | +          throw new \InvalidArgumentException("\$key must be a not empty string."); | |
| 447 | + } | |
| 431 | 448 | |
| 432 | 449 | $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key)); | 
| 433 | 450 | } | 
| @@ -454,11 +471,13 @@ discard block | ||
| 454 | 471 | * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session | 
| 455 | 472 | */ | 
| 456 | 473 |    public function setSession($userName, $password) { | 
| 457 | - if (!is_string($userName) or empty($userName)) | |
| 458 | -      throw new \InvalidArgumentException("\$userName must be a not empty string."); | |
| 474 | +    if (!is_string($userName) or empty($userName)) { | |
| 475 | +          throw new \InvalidArgumentException("\$userName must be a not empty string."); | |
| 476 | + } | |
| 459 | 477 | |
| 460 | - if (!is_string($password) or empty($password)) | |
| 461 | -      throw new \InvalidArgumentException("\$password must be a not empty string."); | |
| 478 | +    if (!is_string($password) or empty($password)) { | |
| 479 | +          throw new \InvalidArgumentException("\$password must be a not empty string."); | |
| 480 | + } | |
| 462 | 481 | |
| 463 | 482 | $request = new Request(Request::POST_METHOD, "/_session"); | 
| 464 | 483 | |
| @@ -545,8 +564,9 @@ discard block | ||
| 545 | 564 | # One of the characters “_$()” «_$()» | 
| 546 | 565 | # A character in the range between “+” and “/” «+-/» | 
| 547 | 566 | # Assert position at the very end of the string «\z» | 
| 548 | -    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) | |
| 549 | -      throw new \InvalidArgumentException("Invalid database name."); | |
| 567 | +    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) { | |
| 568 | +          throw new \InvalidArgumentException("Invalid database name."); | |
| 569 | + } | |
| 550 | 570 | |
| 551 | 571 | $this->send(new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$name)."/")); | 
| 552 | 572 | } | 
| @@ -584,8 +604,9 @@ discard block | ||
| 584 | 604 |    public function getDbChanges($name, Opt\ChangesFeedOpts $opts = NULL) { | 
| 585 | 605 | $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$name)."/_changes"); | 
| 586 | 606 | |
| 587 | - if (isset($opts)) | |
| 588 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 607 | +    if (isset($opts)) { | |
| 608 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 609 | + } | |
| 589 | 610 | |
| 590 | 611 | return $this->send($request); | 
| 591 | 612 | } | 
| @@ -774,40 +795,47 @@ discard block | ||
| 774 | 795 |        is_string($targetDbUrl) && !empty($targetDbUrl)) { | 
| 775 | 796 | $body["source"] = $sourceDbUrl; | 
| 776 | 797 | $body["target"] = $targetDbUrl; | 
| 798 | +    } else { | |
| 799 | +          throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); | |
| 777 | 800 | } | 
| 778 | - else | |
| 779 | -      throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); | |
| 780 | 801 | |
| 781 | - if (!is_bool($continuous)) | |
| 782 | -      throw new \InvalidArgumentException("\$continuous must be a bool."); | |
| 783 | - elseif ($continuous) | |
| 784 | - $body["continuous"] = $continuous; | |
| 802 | +    if (!is_bool($continuous)) { | |
| 803 | +          throw new \InvalidArgumentException("\$continuous must be a bool."); | |
| 804 | +    } elseif ($continuous) { | |
| 805 | + $body["continuous"] = $continuous; | |
| 806 | + } | |
| 785 | 807 | |
| 786 | 808 | // Uses the specified proxy if any set. | 
| 787 | - if (isset($proxy)) | |
| 788 | - $body["proxy"] = $proxy; | |
| 809 | +    if (isset($proxy)) { | |
| 810 | + $body["proxy"] = $proxy; | |
| 811 | + } | |
| 789 | 812 | |
| 790 | 813 | // create_target option | 
| 791 | - if (!is_bool($createTargetDb)) | |
| 792 | -      throw new \InvalidArgumentException("\$createTargetDb must be a bool."); | |
| 793 | - elseif ($createTargetDb) | |
| 794 | - $body["create_target"] = $createTargetDb; | |
| 814 | +    if (!is_bool($createTargetDb)) { | |
| 815 | +          throw new \InvalidArgumentException("\$createTargetDb must be a bool."); | |
| 816 | +    } elseif ($createTargetDb) { | |
| 817 | + $body["create_target"] = $createTargetDb; | |
| 818 | + } | |
| 795 | 819 | |
| 796 | 820 |      if (!empty($filter)) { | 
| 797 | - if (is_string($filter)) // filter option | |
| 821 | +      if (is_string($filter)) { | |
| 822 | + // filter option | |
| 798 | 823 | $body["filter"] = $filter; | 
| 799 | - elseif (is_array($filter)) // doc_ids option | |
| 824 | +      } elseif (is_array($filter)) { | |
| 825 | + // doc_ids option | |
| 800 | 826 | $body["doc_ids"] = array_values($filter); | 
| 801 | - else | |
| 802 | -        throw new \InvalidArgumentException("\$filter must be a string or an array."); | |
| 827 | +      } else { | |
| 828 | +              throw new \InvalidArgumentException("\$filter must be a string or an array."); | |
| 829 | + } | |
| 803 | 830 | } | 
| 804 | 831 | |
| 805 | 832 | // queryParams option | 
| 806 | 833 |      if (!is_null($opts)) { | 
| 807 | - if ($opts instanceof Opt\ViewQueryOpts) | |
| 808 | - $body["query_params"] = get_object_vars($opts); | |
| 809 | - else | |
| 810 | -        throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); | |
| 834 | +      if ($opts instanceof Opt\ViewQueryOpts) { | |
| 835 | + $body["query_params"] = get_object_vars($opts); | |
| 836 | +      } else { | |
| 837 | +              throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); | |
| 838 | + } | |
| 811 | 839 | } | 
| 812 | 840 | |
| 813 | 841 | $request = new Request(Request::POST_METHOD, "/_replicate"); | 
| @@ -824,8 +852,9 @@ discard block | ||
| 824 | 852 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication | 
| 825 | 853 | */ | 
| 826 | 854 |    public function stopReplication($replicationId) { | 
| 827 | - if (is_null($replicationId)) | |
| 828 | -      throw new \InvalidArgumentException("You must provide a replication id."); | |
| 855 | +    if (is_null($replicationId)) { | |
| 856 | +          throw new \InvalidArgumentException("You must provide a replication id."); | |
| 857 | + } | |
| 829 | 858 | |
| 830 | 859 | $body["replication_id"] = $replicationId; | 
| 831 | 860 | $body["cancel"] = TRUE; | 
| @@ -874,15 +903,16 @@ discard block | ||
| 874 | 903 | * @see http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs | 
| 875 | 904 | */ | 
| 876 | 905 |    public function queryAllDocs($dbName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { | 
| 877 | - if (is_null($keys)) | |
| 878 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); | |
| 879 | -    else { | |
| 906 | +    if (is_null($keys)) { | |
| 907 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); | |
| 908 | +    } else { | |
| 880 | 909 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs"); | 
| 881 | 910 | $request->setBody(json_encode(['keys' => $keys])); | 
| 882 | 911 | } | 
| 883 | 912 | |
| 884 | - if (isset($opts)) | |
| 885 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 913 | +    if (isset($opts)) { | |
| 914 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); | |
| 915 | + } | |
| 886 | 916 | |
| 887 | 917 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); | 
| 888 | 918 | |
| @@ -911,12 +941,13 @@ discard block | ||
| 911 | 941 |    public function queryView($dbName, $designDocName, $viewName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { | 
| 912 | 942 | $this->validateAndEncodeDocId($designDocName); | 
| 913 | 943 | |
| 914 | - if (empty($viewName)) | |
| 915 | -      throw new \InvalidArgumentException("You must provide a valid \$viewName."); | |
| 944 | +    if (empty($viewName)) { | |
| 945 | +          throw new \InvalidArgumentException("You must provide a valid \$viewName."); | |
| 946 | + } | |
| 916 | 947 | |
| 917 | - if (empty($keys)) | |
| 918 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); | |
| 919 | -    else { | |
| 948 | +    if (empty($keys)) { | |
| 949 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); | |
| 950 | +    } else { | |
| 920 | 951 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName); | 
| 921 | 952 | $request->setBody(json_encode(['keys' => $keys])); | 
| 922 | 953 | } | 
| @@ -927,14 +958,15 @@ discard block | ||
| 927 | 958 |      if (isset($opts)) { | 
| 928 | 959 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); | 
| 929 | 960 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); | 
| 961 | +    } else { | |
| 962 | + $includeMissingKeys = FALSE; | |
| 930 | 963 | } | 
| 931 | - else | |
| 932 | - $includeMissingKeys = FALSE; | |
| 933 | 964 | |
| 934 | 965 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); | 
| 935 | 966 | |
| 936 | - if ($includeMissingKeys) | |
| 937 | - $this->addMissingRows($keys, $result['rows']); | |
| 967 | +    if ($includeMissingKeys) { | |
| 968 | + $this->addMissingRows($keys, $result['rows']); | |
| 969 | + } | |
| 938 | 970 | |
| 939 | 971 | return new Result\QueryResult($result); | 
| 940 | 972 | } | 
| @@ -961,30 +993,33 @@ discard block | ||
| 961 | 993 |      $handler = new Handler\ViewHandler('temp'); | 
| 962 | 994 | $handler->language = $language; | 
| 963 | 995 | $handler->mapFn = $mapFn; | 
| 964 | - if (!empty($reduce)) | |
| 965 | - $handler->reduceFn = $reduceFn; | |
| 996 | +    if (!empty($reduce)) { | |
| 997 | + $handler->reduceFn = $reduceFn; | |
| 998 | + } | |
| 966 | 999 | |
| 967 | 1000 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_temp_view"); | 
| 968 | 1001 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); | 
| 969 | 1002 | |
| 970 | 1003 | $array = $handler->asArray(); | 
| 971 | 1004 | |
| 972 | - if (!empty($keys)) | |
| 973 | - $array['keys'] = $keys; | |
| 1005 | +    if (!empty($keys)) { | |
| 1006 | + $array['keys'] = $keys; | |
| 1007 | + } | |
| 974 | 1008 | |
| 975 | 1009 | $request->setBody(json_encode($array)); | 
| 976 | 1010 | |
| 977 | 1011 |      if (isset($opts)) { | 
| 978 | 1012 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); | 
| 979 | 1013 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); | 
| 1014 | +    } else { | |
| 1015 | + $includeMissingKeys = FALSE; | |
| 980 | 1016 | } | 
| 981 | - else | |
| 982 | - $includeMissingKeys = FALSE; | |
| 983 | 1017 | |
| 984 | 1018 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); | 
| 985 | 1019 | |
| 986 | - if ($includeMissingKeys) | |
| 987 | - $this->addMissingRows($keys, $result['rows']); | |
| 1020 | +    if ($includeMissingKeys) { | |
| 1021 | + $this->addMissingRows($keys, $result['rows']); | |
| 1022 | + } | |
| 988 | 1023 | |
| 989 | 1024 | return new Result\QueryResult($result); | 
| 990 | 1025 | } | 
| @@ -1043,8 +1078,9 @@ discard block | ||
| 1043 | 1078 | * @see http://docs.couchdb.org/en/latest/api/database/misc.html#put--db-_revs_limit | 
| 1044 | 1079 | */ | 
| 1045 | 1080 |    public function setRevsLimit($dbName, $revsLimit = self::REVS_LIMIT) { | 
| 1046 | - if (!is_int($revsLimit) or ($revsLimit <= 0)) | |
| 1047 | -      throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); | |
| 1081 | +    if (!is_int($revsLimit) or ($revsLimit <= 0)) { | |
| 1082 | +          throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); | |
| 1083 | + } | |
| 1048 | 1084 | |
| 1049 | 1085 | $request = new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_revs_limit"); | 
| 1050 | 1086 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); | 
| @@ -1103,16 +1139,17 @@ discard block | ||
| 1103 | 1139 | $request = new Request(Request::GET_METHOD, $requestPath); | 
| 1104 | 1140 | |
| 1105 | 1141 | // Retrieves the specific revision of the document. | 
| 1106 | - if (!empty($rev)) | |
| 1107 | -      $request->setQueryParam("rev", (string)$rev); | |
| 1142 | +    if (!empty($rev)) { | |
| 1143 | +          $request->setQueryParam("rev", (string)$rev); | |
| 1144 | + } | |
| 1108 | 1145 | |
| 1109 | 1146 | // If there are any options, add them to the request. | 
| 1110 | 1147 |      if (isset($opts)) { | 
| 1111 | 1148 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); | 
| 1112 | 1149 | $ignoreClass = $opts->issetIgnoreClass(); | 
| 1150 | +    } else { | |
| 1151 | + $ignoreClass = FALSE; | |
| 1113 | 1152 | } | 
| 1114 | - else | |
| 1115 | - $ignoreClass = FALSE; | |
| 1116 | 1153 | |
| 1117 | 1154 | $response = $this->send($request); | 
| 1118 | 1155 | $body = $response->getBodyAsArray(); | 
| @@ -1124,18 +1161,18 @@ discard block | ||
| 1124 | 1161 |      if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc. | 
| 1125 | 1162 | $class = "\\".$body['class']; | 
| 1126 | 1163 | $doc = new $class; | 
| 1164 | +    } elseif ($path == self::DESIGN_DOC_PATH) { | |
| 1165 | + $doc = new Doc\DesignDoc; | |
| 1166 | +    } else { | |
| 1167 | + $doc = NULL; | |
| 1127 | 1168 | } | 
| 1128 | - elseif ($path == self::DESIGN_DOC_PATH) | |
| 1129 | - $doc = new Doc\DesignDoc; | |
| 1130 | - else | |
| 1131 | - $doc = NULL; | |
| 1132 | 1169 | |
| 1133 | 1170 |      if (is_object($doc)) { | 
| 1134 | 1171 | $doc->assignArray($body); | 
| 1135 | 1172 | return $doc; | 
| 1173 | +    } else { | |
| 1174 | + return $response; | |
| 1136 | 1175 | } | 
| 1137 | - else | |
| 1138 | - return $response; | |
| 1139 | 1176 | } | 
| 1140 | 1177 | |
| 1141 | 1178 | |
| @@ -1155,8 +1192,9 @@ discard block | ||
| 1155 | 1192 |    public function saveDoc($dbName, Doc\IDoc $doc, $batchMode = FALSE) { | 
| 1156 | 1193 | // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc | 
| 1157 | 1194 | // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. | 
| 1158 | - if (!$doc->issetId()) | |
| 1159 | - $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); | |
| 1195 | +    if (!$doc->issetId()) { | |
| 1196 | + $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); | |
| 1197 | + } | |
| 1160 | 1198 | |
| 1161 | 1199 | $this->setDocInfo($doc); | 
| 1162 | 1200 | |
| @@ -1170,8 +1208,9 @@ discard block | ||
| 1170 | 1208 | $request->setBody($doc->asJson()); | 
| 1171 | 1209 | |
| 1172 | 1210 | // Enables batch mode. | 
| 1173 | - if ($batchMode) | |
| 1174 | -      $request->setQueryParam("batch", "ok"); | |
| 1211 | +    if ($batchMode) { | |
| 1212 | +          $request->setQueryParam("batch", "ok"); | |
| 1213 | + } | |
| 1175 | 1214 | |
| 1176 | 1215 | $this->send($request); | 
| 1177 | 1216 | } | 
| @@ -1224,10 +1263,11 @@ discard block | ||
| 1224 | 1263 | // This request uses the special method COPY. | 
| 1225 | 1264 | $request = new Request(Request::COPY_METHOD, $path); | 
| 1226 | 1265 | |
| 1227 | - if (empty($rev)) | |
| 1228 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); | |
| 1229 | - else | |
| 1230 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); | |
| 1266 | +    if (empty($rev)) { | |
| 1267 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); | |
| 1268 | +    } else { | |
| 1269 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); | |
| 1270 | + } | |
| 1231 | 1271 | |
| 1232 | 1272 | $this->send($request); | 
| 1233 | 1273 | } | 
| @@ -1256,8 +1296,9 @@ discard block | ||
| 1256 | 1296 | $request = new Request(Request::POST_METHOD, $path); | 
| 1257 | 1297 | |
| 1258 | 1298 | $purge = []; | 
| 1259 | - foreach ($refs as $ref) | |
| 1260 | - $purge[] = $ref->asArray(); | |
| 1299 | +    foreach ($refs as $ref) { | |
| 1300 | + $purge[] = $ref->asArray(); | |
| 1301 | + } | |
| 1261 | 1302 | |
| 1262 | 1303 | $request->setBody(json_encode($purge)); | 
| 1263 | 1304 | |
| @@ -1289,26 +1330,30 @@ discard block | ||
| 1289 | 1330 | * @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API | 
| 1290 | 1331 | */ | 
| 1291 | 1332 |    public function performBulkOperations($dbName, array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) { | 
| 1292 | - if (count($docs) == 0) | |
| 1293 | -      throw new \InvalidArgumentException("The \$docs array cannot be empty."); | |
| 1294 | - else | |
| 1295 | - $operations = []; | |
| 1333 | +    if (count($docs) == 0) { | |
| 1334 | +          throw new \InvalidArgumentException("The \$docs array cannot be empty."); | |
| 1335 | +    } else { | |
| 1336 | + $operations = []; | |
| 1337 | + } | |
| 1296 | 1338 | |
| 1297 | 1339 | $path = "/".rawurlencode($this->prefix.$dbName)."/_bulk_docs"; | 
| 1298 | 1340 | |
| 1299 | 1341 | $request = new Request(Request::POST_METHOD, $path); | 
| 1300 | 1342 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); | 
| 1301 | 1343 | |
| 1302 | - if ($fullCommit) | |
| 1303 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); | |
| 1304 | - else | |
| 1305 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); | |
| 1344 | +    if ($fullCommit) { | |
| 1345 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); | |
| 1346 | +    } else { | |
| 1347 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); | |
| 1348 | + } | |
| 1306 | 1349 | |
| 1307 | - if ($allOrNothing) | |
| 1308 | - $operations['all_or_nothing'] = 'true'; | |
| 1350 | +    if ($allOrNothing) { | |
| 1351 | + $operations['all_or_nothing'] = 'true'; | |
| 1352 | + } | |
| 1309 | 1353 | |
| 1310 | - if (!$newEdits) | |
| 1311 | - $operations['new_edits'] = 'false'; | |
| 1354 | +    if (!$newEdits) { | |
| 1355 | + $operations['new_edits'] = 'false'; | |
| 1356 | + } | |
| 1312 | 1357 | |
| 1313 | 1358 |      foreach ($docs as $doc) { | 
| 1314 | 1359 | $this->setDocInfo($doc); | 
| @@ -1346,8 +1391,9 @@ discard block | ||
| 1346 | 1391 | $request = new Request(Request::HEAD_METHOD, $path); | 
| 1347 | 1392 | |
| 1348 | 1393 | // In case we want retrieve a specific document revision. | 
| 1349 | - if (!empty($rev)) | |
| 1350 | -      $request->setQueryParam("rev", (string)$rev); | |
| 1394 | +    if (!empty($rev)) { | |
| 1395 | +          $request->setQueryParam("rev", (string)$rev); | |
| 1396 | + } | |
| 1351 | 1397 | |
| 1352 | 1398 | return $this->send($request); | 
| 1353 | 1399 | } | 
| @@ -1373,8 +1419,9 @@ discard block | ||
| 1373 | 1419 | $request = new Request(Request::GET_METHOD, $path); | 
| 1374 | 1420 | |
| 1375 | 1421 | // In case we want retrieve a specific document revision. | 
| 1376 | - if (!empty($rev)) | |
| 1377 | -      $request->setQueryParam("rev", (string)$rev); | |
| 1422 | +    if (!empty($rev)) { | |
| 1423 | +          $request->setQueryParam("rev", (string)$rev); | |
| 1424 | + } | |
| 1378 | 1425 | |
| 1379 | 1426 | return $this->send($request)->getBody(); | 
| 1380 | 1427 | } | 
| @@ -1403,8 +1450,9 @@ discard block | ||
| 1403 | 1450 | $request->setBody(base64_encode($attachment->getData())); | 
| 1404 | 1451 | |
| 1405 | 1452 | // In case of adding or updating an existence document. | 
| 1406 | - if (!empty($rev)) | |
| 1407 | -      $request->setQueryParam("rev", (string)$rev); | |
| 1453 | +    if (!empty($rev)) { | |
| 1454 | +          $request->setQueryParam("rev", (string)$rev); | |
| 1455 | + } | |
| 1408 | 1456 | |
| 1409 | 1457 | return $this->send($request); | 
| 1410 | 1458 | } | 
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | * configurations.\n | 
| 18 | 18 | * Inherit from LocalDoc if you want create a persistent class that is not replicable. | 
| 19 | 19 | * @nosubgrouping | 
| 20 | - */ | |
| 20 | + */ | |
| 21 | 21 |  class LocalDoc extends AbstractDoc { | 
| 22 | 22 | |
| 23 | 23 | |
| @@ -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 | |
| @@ -144,8 +144,9 @@ discard block | ||
| 144 | 144 |    public static function checkFn($fnImpl, $fnDef, $fnRegex) { | 
| 145 | 145 | Lint::checkSourceCode($fnImpl); | 
| 146 | 146 | |
| 147 | - if (!preg_match($fnRegex, $fnImpl)) | |
| 148 | -      throw new \Exception("The \$closure must be defined like: $fnDef"); | |
| 147 | +    if (!preg_match($fnRegex, $fnImpl)) { | |
| 148 | +          throw new \Exception("The \$closure must be defined like: $fnDef"); | |
| 149 | + } | |
| 149 | 150 | } | 
| 150 | 151 | |
| 151 | 152 | |
| @@ -153,14 +154,17 @@ discard block | ||
| 153 | 154 | $view = []; | 
| 154 | 155 | $view['map'] = $this->mapFn; | 
| 155 | 156 | |
| 156 | - if (!empty($this->language)) | |
| 157 | - $view['language'] = $this->language; | |
| 157 | +    if (!empty($this->language)) { | |
| 158 | + $view['language'] = $this->language; | |
| 159 | + } | |
| 158 | 160 | |
| 159 | - if (!empty($this->reduceFn)) | |
| 160 | - $view['reduce'] = $this->reduceFn; | |
| 161 | +    if (!empty($this->reduceFn)) { | |
| 162 | + $view['reduce'] = $this->reduceFn; | |
| 163 | + } | |
| 161 | 164 | |
| 162 | - if (!empty($this->options)) | |
| 163 | - $view['options'] = $this->options; | |
| 165 | +    if (!empty($this->options)) { | |
| 166 | + $view['options'] = $this->options; | |
| 167 | + } | |
| 164 | 168 | |
| 165 | 169 | return $view; | 
| 166 | 170 | } | 
| @@ -225,8 +229,9 @@ discard block | ||
| 225 | 229 |    public function setMapFn($value) { | 
| 226 | 230 | $fn = stripslashes((string)$value); | 
| 227 | 231 | |
| 228 | - if ($this->language == "php") | |
| 229 | - self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); | |
| 232 | +    if ($this->language == "php") { | |
| 233 | + self::checkFn($fn, self::MAP_DEFINITION, self::MAP_REGEX); | |
| 234 | + } | |
| 230 | 235 | |
| 231 | 236 | $this->mapFn = $fn; | 
| 232 | 237 | } | 
| @@ -240,8 +245,9 @@ discard block | ||
| 240 | 245 |    public function setReduceFn($value) { | 
| 241 | 246 | $fn = stripslashes((string)$value); | 
| 242 | 247 | |
| 243 | - if ($this->language == "php") | |
| 244 | - self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); | |
| 248 | +    if ($this->language == "php") { | |
| 249 | + self::checkFn($fn, self::REDUCE_DEFINITION, self::REDUCE_REGEX); | |
| 250 | + } | |
| 245 | 251 | |
| 246 | 252 | $this->reduceFn = $fn; | 
| 247 | 253 | } | 
| @@ -36,8 +36,9 @@ discard block | ||
| 36 | 36 | * @attention Chainable. | 
| 37 | 37 | */ | 
| 38 | 38 |    public function unsetOpt($name) { | 
| 39 | - if (array_key_exists($name, $this->options)) | |
| 40 | - unset($this->options['name']); | |
| 39 | +    if (array_key_exists($name, $this->options)) { | |
| 40 | + unset($this->options['name']); | |
| 41 | + } | |
| 41 | 42 | |
| 42 | 43 | return $this; | 
| 43 | 44 | } | 
| @@ -137,10 +138,11 @@ discard block | ||
| 137 | 138 | * @attention Chainable. | 
| 138 | 139 | */ | 
| 139 | 140 |    public function setLimit($value) { | 
| 140 | - if (is_int($value) && $value >= 0) | |
| 141 | - $this->options["limit"] = $value; | |
| 142 | - else | |
| 143 | -      throw new \Exception("\$value must be a non-negative integer."); | |
| 141 | +    if (is_int($value) && $value >= 0) { | |
| 142 | + $this->options["limit"] = $value; | |
| 143 | +    } else { | |
| 144 | +          throw new \Exception("\$value must be a non-negative integer."); | |
| 145 | + } | |
| 144 | 146 | |
| 145 | 147 | return $this; | 
| 146 | 148 | } | 
| @@ -173,9 +175,9 @@ discard block | ||
| 173 | 175 |      if (is_int($value) && $value > 0) { | 
| 174 | 176 | $this->options["group"] = "false"; // This parameter is used only if 'group' is 'false'. | 
| 175 | 177 | $this->options["group_level"] = $value; | 
| 178 | +    } else { | |
| 179 | +          throw new \Exception("\$value must be a positive integer."); | |
| 176 | 180 | } | 
| 177 | - else | |
| 178 | -      throw new \Exception("\$value must be a positive integer."); | |
| 179 | 181 | |
| 180 | 182 | return $this; | 
| 181 | 183 | } | 
| @@ -311,10 +313,11 @@ discard block | ||
| 311 | 313 | * @attention Chainable. | 
| 312 | 314 | */ | 
| 313 | 315 |    public function skipDocs($number) { | 
| 314 | - if (is_int($number) && $number > 0) | |
| 315 | - $this->options["skip"] = $number; | |
| 316 | - else | |
| 317 | -      throw new \Exception("\$number must be a positive integer."); | |
| 316 | +    if (is_int($number) && $number > 0) { | |
| 317 | + $this->options["skip"] = $number; | |
| 318 | +    } else { | |
| 319 | +          throw new \Exception("\$number must be a positive integer."); | |
| 320 | + } | |
| 318 | 321 | |
| 319 | 322 | return $this; | 
| 320 | 323 | } |