@@ -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");  | 
                                                        
@@ -16,7 +16,6 @@  | 
                                                    ||
| 16 | 16 | use Surfer\Message\Request;  | 
                                                        
| 17 | 17 | use Surfer\Message\Response;  | 
                                                        
| 18 | 18 | use Surfer\Hook\IChunkHook;  | 
                                                        
| 19 | -  | 
                                                        |
| 20 | 19 | use stdClass;  | 
                                                        
| 21 | 20 | |
| 22 | 21 | |
@@ -107,10 +107,13 @@ discard block  | 
                                                    ||
| 107 | 107 |        foreach ($keys as $key) { | 
                                                        
| 108 | 108 | $hash = md5(json_encode($key));  | 
                                                        
| 109 | 109 | |
| 110 | - if (isset($matches[$hash])) // Match found.  | 
                                                        |
| 110 | +        if (isset($matches[$hash])) { | 
                                                        |
| 111 | + // Match found.  | 
                                                        |
| 111 | 112 | $allRows[] = $matches[$hash];  | 
                                                        
| 112 | - else // No match found.  | 
                                                        |
| 113 | +        } else { | 
                                                        |
| 114 | + // No match found.  | 
                                                        |
| 113 | 115 | $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL];  | 
                                                        
| 116 | + }  | 
                                                        |
| 114 | 117 | }  | 
                                                        
| 115 | 118 | |
| 116 | 119 | // Overrides the response, replacing rows.  | 
                                                        
@@ -173,15 +176,18 @@ discard block  | 
                                                    ||
| 173 | 176 | * @param bool $excludeLocal Document path.  | 
                                                        
| 174 | 177 | */  | 
                                                        
| 175 | 178 |    public function validateDocPath($path, $excludeLocal = FALSE) { | 
                                                        
| 176 | - if (empty($path)) // STD_DOC_PATH  | 
                                                        |
| 179 | +    if (empty($path)) { | 
                                                        |
| 180 | + // STD_DOC_PATH  | 
                                                        |
| 177 | 181 | return;  | 
                                                        
| 182 | + }  | 
                                                        |
| 178 | 183 | |
| 179 | - if ($path == self::DESIGN_DOC_PATH)  | 
                                                        |
| 180 | - return;  | 
                                                        |
| 181 | - elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal)  | 
                                                        |
| 182 | -      throw new \InvalidArgumentException("Local document doesn't have attachments."); | 
                                                        |
| 183 | - else  | 
                                                        |
| 184 | -      throw new \InvalidArgumentException("Invalid document path."); | 
                                                        |
| 184 | +    if ($path == self::DESIGN_DOC_PATH) { | 
                                                        |
| 185 | + return;  | 
                                                        |
| 186 | +    } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) { | 
                                                        |
| 187 | +          throw new \InvalidArgumentException("Local document doesn't have attachments."); | 
                                                        |
| 188 | +    } else { | 
                                                        |
| 189 | +          throw new \InvalidArgumentException("Invalid document path."); | 
                                                        |
| 190 | + }  | 
                                                        |
| 185 | 191 | }  | 
                                                        
| 186 | 192 | |
| 187 | 193 | |
@@ -192,10 +198,11 @@ discard block  | 
                                                    ||
| 192 | 198 | * @param string $docId Document id.  | 
                                                        
| 193 | 199 | */  | 
                                                        
| 194 | 200 |    public function validateAndEncodeDocId(&$docId) { | 
                                                        
| 195 | - if (!empty($docId))  | 
                                                        |
| 196 | - $docId = rawurlencode($docId);  | 
                                                        |
| 197 | - else  | 
                                                        |
| 198 | -      throw new \InvalidArgumentException("\$docId must be a non-empty string."); | 
                                                        |
| 201 | +    if (!empty($docId)) { | 
                                                        |
| 202 | + $docId = rawurlencode($docId);  | 
                                                        |
| 203 | +    } else { | 
                                                        |
| 204 | +          throw new \InvalidArgumentException("\$docId must be a non-empty string."); | 
                                                        |
| 205 | + }  | 
                                                        |
| 199 | 206 | }  | 
                                                        
| 200 | 207 | |
| 201 | 208 | //!@}  | 
                                                        
@@ -227,10 +234,10 @@ discard block  | 
                                                    ||
| 227 | 234 | // before the client has received the entire response. To avoid problems, we trap the exception and we go on.  | 
                                                        
| 228 | 235 |      try { | 
                                                        
| 229 | 236 | $this->send($request);  | 
                                                        
| 230 | - }  | 
                                                        |
| 231 | -    catch (\Exception $e) { | 
                                                        |
| 232 | - if ($e->getCode() > 0)  | 
                                                        |
| 233 | - throw $e;  | 
                                                        |
| 237 | +    } catch (\Exception $e) { | 
                                                        |
| 238 | +      if ($e->getCode() > 0) { | 
                                                        |
| 239 | + throw $e;  | 
                                                        |
| 240 | + }  | 
                                                        |
| 234 | 241 | }  | 
                                                        
| 235 | 242 | }  | 
                                                        
| 236 | 243 | |
@@ -267,10 +274,11 @@ discard block  | 
                                                    ||
| 267 | 274 |    public function getFavicon() { | 
                                                        
| 268 | 275 | $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico"));  | 
                                                        
| 269 | 276 | |
| 270 | - if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon")  | 
                                                        |
| 271 | - return $response->getBody();  | 
                                                        |
| 272 | - else  | 
                                                        |
| 273 | -      throw new \InvalidArgumentException("Content-Type must be image/x-icon."); | 
                                                        |
| 277 | +    if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") { | 
                                                        |
| 278 | + return $response->getBody();  | 
                                                        |
| 279 | +    } else { | 
                                                        |
| 280 | +          throw new \InvalidArgumentException("Content-Type must be image/x-icon."); | 
                                                        |
| 281 | + }  | 
                                                        |
| 274 | 282 | }  | 
                                                        
| 275 | 283 | |
| 276 | 284 | |
@@ -304,8 +312,9 @@ discard block  | 
                                                    ||
| 304 | 312 |    public function getDbUpdates(Opt\DbUpdatesFeedOpts $opts = NULL) { | 
                                                        
| 305 | 313 | $request = new Request(Request::GET_METHOD, "/_db_updates");  | 
                                                        
| 306 | 314 | |
| 307 | - if (isset($opts))  | 
                                                        |
| 308 | - $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 315 | +    if (isset($opts)) { | 
                                                        |
| 316 | + $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 317 | + }  | 
                                                        |
| 309 | 318 | |
| 310 | 319 | return $this->send($request)->getBodyAsArray();  | 
                                                        
| 311 | 320 | }  | 
                                                        
@@ -334,9 +343,9 @@ discard block  | 
                                                    ||
| 334 | 343 | $request = new Request(Request::GET_METHOD, "/_log");  | 
                                                        
| 335 | 344 |        $request->setQueryParam("bytes", $bytes); | 
                                                        
| 336 | 345 | return $this->send($request)->getBody();  | 
                                                        
| 346 | +    } else { | 
                                                        |
| 347 | +          throw new \InvalidArgumentException("\$bytes must be a positive integer."); | 
                                                        |
| 337 | 348 | }  | 
                                                        
| 338 | - else  | 
                                                        |
| 339 | -      throw new \InvalidArgumentException("\$bytes must be a positive integer."); | 
                                                        |
| 340 | 349 | }  | 
                                                        
| 341 | 350 | |
| 342 | 351 | |
@@ -353,13 +362,15 @@ discard block  | 
                                                    ||
| 353 | 362 | |
| 354 | 363 | $response = $this->send($request);  | 
                                                        
| 355 | 364 | |
| 356 | - if ($count == 1) // We don't need to use === operator because, just above, we made a type checking.  | 
                                                        |
| 365 | +      if ($count == 1) { | 
                                                        |
| 366 | + // We don't need to use === operator because, just above, we made a type checking.  | 
                                                        |
| 357 | 367 | return $response->getBodyAsArray()['uuids'][0];  | 
                                                        
| 358 | - else  | 
                                                        |
| 359 | - return $response->getBodyAsArray()['uuids'];  | 
                                                        |
| 368 | +      } else { | 
                                                        |
| 369 | + return $response->getBodyAsArray()['uuids'];  | 
                                                        |
| 370 | + }  | 
                                                        |
| 371 | +    } else { | 
                                                        |
| 372 | +          throw new \InvalidArgumentException("\$count must be a positive integer."); | 
                                                        |
| 360 | 373 | }  | 
                                                        
| 361 | - else  | 
                                                        |
| 362 | -      throw new \InvalidArgumentException("\$count must be a positive integer."); | 
                                                        |
| 363 | 374 | }  | 
                                                        
| 364 | 375 | |
| 365 | 376 | //!@}  | 
                                                        
@@ -383,8 +394,9 @@ discard block  | 
                                                    ||
| 383 | 394 |      if (!empty($section)) { | 
                                                        
| 384 | 395 | $path .= "/".$section;  | 
                                                        
| 385 | 396 | |
| 386 | - if (!empty($key))  | 
                                                        |
| 387 | - $path .= "/".$key;  | 
                                                        |
| 397 | +      if (!empty($key)) { | 
                                                        |
| 398 | + $path .= "/".$key;  | 
                                                        |
| 399 | + }  | 
                                                        |
| 388 | 400 | }  | 
                                                        
| 389 | 401 | |
| 390 | 402 | return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray();  | 
                                                        
@@ -399,14 +411,17 @@ discard block  | 
                                                    ||
| 399 | 411 | * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key  | 
                                                        
| 400 | 412 | */  | 
                                                        
| 401 | 413 |    public function setConfigKey($section, $key, $value) { | 
                                                        
| 402 | - if (!is_string($section) || empty($section))  | 
                                                        |
| 403 | -      throw new \InvalidArgumentException("\$section must be a not empty string."); | 
                                                        |
| 414 | +    if (!is_string($section) || empty($section)) { | 
                                                        |
| 415 | +          throw new \InvalidArgumentException("\$section must be a not empty string."); | 
                                                        |
| 416 | + }  | 
                                                        |
| 404 | 417 | |
| 405 | - if (!is_string($key) || empty($key))  | 
                                                        |
| 406 | -      throw new \InvalidArgumentException("\$key must be a not empty string."); | 
                                                        |
| 418 | +    if (!is_string($key) || empty($key)) { | 
                                                        |
| 419 | +          throw new \InvalidArgumentException("\$key must be a not empty string."); | 
                                                        |
| 420 | + }  | 
                                                        |
| 407 | 421 | |
| 408 | - if (is_null($value))  | 
                                                        |
| 409 | -      throw new \InvalidArgumentException("\$value cannot be null."); | 
                                                        |
| 422 | +    if (is_null($value)) { | 
                                                        |
| 423 | +          throw new \InvalidArgumentException("\$value cannot be null."); | 
                                                        |
| 424 | + }  | 
                                                        |
| 410 | 425 | |
| 411 | 426 | $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key);  | 
                                                        
| 412 | 427 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");  | 
                                                        
@@ -422,11 +437,13 @@ discard block  | 
                                                    ||
| 422 | 437 | * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key  | 
                                                        
| 423 | 438 | */  | 
                                                        
| 424 | 439 |    public function deleteConfigKey($section, $key) { | 
                                                        
| 425 | - if (!is_string($section) || empty($section))  | 
                                                        |
| 426 | -      throw new \InvalidArgumentException("\$section must be a not empty string."); | 
                                                        |
| 440 | +    if (!is_string($section) || empty($section)) { | 
                                                        |
| 441 | +          throw new \InvalidArgumentException("\$section must be a not empty string."); | 
                                                        |
| 442 | + }  | 
                                                        |
| 427 | 443 | |
| 428 | - if (!is_string($key) || empty($key))  | 
                                                        |
| 429 | -      throw new \InvalidArgumentException("\$key must be a not empty string."); | 
                                                        |
| 444 | +    if (!is_string($key) || empty($key)) { | 
                                                        |
| 445 | +          throw new \InvalidArgumentException("\$key must be a not empty string."); | 
                                                        |
| 446 | + }  | 
                                                        |
| 430 | 447 | |
| 431 | 448 | $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key));  | 
                                                        
| 432 | 449 | }  | 
                                                        
@@ -453,11 +470,13 @@ discard block  | 
                                                    ||
| 453 | 470 | * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session  | 
                                                        
| 454 | 471 | */  | 
                                                        
| 455 | 472 |    public function setSession($userName, $password) { | 
                                                        
| 456 | - if (!is_string($userName) || empty($userName))  | 
                                                        |
| 457 | -      throw new \InvalidArgumentException("\$userName must be a not empty string."); | 
                                                        |
| 473 | +    if (!is_string($userName) || empty($userName)) { | 
                                                        |
| 474 | +          throw new \InvalidArgumentException("\$userName must be a not empty string."); | 
                                                        |
| 475 | + }  | 
                                                        |
| 458 | 476 | |
| 459 | - if (!is_string($password) || empty($password))  | 
                                                        |
| 460 | -      throw new \InvalidArgumentException("\$password must be a not empty string."); | 
                                                        |
| 477 | +    if (!is_string($password) || empty($password)) { | 
                                                        |
| 478 | +          throw new \InvalidArgumentException("\$password must be a not empty string."); | 
                                                        |
| 479 | + }  | 
                                                        |
| 461 | 480 | |
| 462 | 481 | $request = new Request(Request::POST_METHOD, "/_session");  | 
                                                        
| 463 | 482 | |
@@ -544,8 +563,9 @@ discard block  | 
                                                    ||
| 544 | 563 | # One of the characters “_$()” «_$()»  | 
                                                        
| 545 | 564 | # A character in the range between “+” and “/” «+-/»  | 
                                                        
| 546 | 565 | # Assert position at the very end of the string «\z»  | 
                                                        
| 547 | -    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) | 
                                                        |
| 548 | -      throw new \InvalidArgumentException("Invalid database name."); | 
                                                        |
| 566 | +    if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name) === FALSE) { | 
                                                        |
| 567 | +          throw new \InvalidArgumentException("Invalid database name."); | 
                                                        |
| 568 | + }  | 
                                                        |
| 549 | 569 | |
| 550 | 570 | $this->send(new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$name)."/"));  | 
                                                        
| 551 | 571 | }  | 
                                                        
@@ -583,8 +603,9 @@ discard block  | 
                                                    ||
| 583 | 603 |    public function getDbChanges($name, Opt\ChangesFeedOpts $opts = NULL) { | 
                                                        
| 584 | 604 | $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$name)."/_changes");  | 
                                                        
| 585 | 605 | |
| 586 | - if (isset($opts))  | 
                                                        |
| 587 | - $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 606 | +    if (isset($opts)) { | 
                                                        |
| 607 | + $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 608 | + }  | 
                                                        |
| 588 | 609 | |
| 589 | 610 | return $this->send($request);  | 
                                                        
| 590 | 611 | }  | 
                                                        
@@ -773,40 +794,47 @@ discard block  | 
                                                    ||
| 773 | 794 |        is_string($targetDbUrl) && !empty($targetDbUrl)) { | 
                                                        
| 774 | 795 | $body["source"] = $sourceDbUrl;  | 
                                                        
| 775 | 796 | $body["target"] = $targetDbUrl;  | 
                                                        
| 797 | +    } else { | 
                                                        |
| 798 | +          throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); | 
                                                        |
| 776 | 799 | }  | 
                                                        
| 777 | - else  | 
                                                        |
| 778 | -      throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); | 
                                                        |
| 779 | 800 | |
| 780 | - if (!is_bool($continuous))  | 
                                                        |
| 781 | -      throw new \InvalidArgumentException("\$continuous must be a bool."); | 
                                                        |
| 782 | - elseif ($continuous)  | 
                                                        |
| 783 | - $body["continuous"] = $continuous;  | 
                                                        |
| 801 | +    if (!is_bool($continuous)) { | 
                                                        |
| 802 | +          throw new \InvalidArgumentException("\$continuous must be a bool."); | 
                                                        |
| 803 | +    } elseif ($continuous) { | 
                                                        |
| 804 | + $body["continuous"] = $continuous;  | 
                                                        |
| 805 | + }  | 
                                                        |
| 784 | 806 | |
| 785 | 807 | // Uses the specified proxy if any set.  | 
                                                        
| 786 | - if (isset($proxy))  | 
                                                        |
| 787 | - $body["proxy"] = $proxy;  | 
                                                        |
| 808 | +    if (isset($proxy)) { | 
                                                        |
| 809 | + $body["proxy"] = $proxy;  | 
                                                        |
| 810 | + }  | 
                                                        |
| 788 | 811 | |
| 789 | 812 | // create_target option  | 
                                                        
| 790 | - if (!is_bool($createTargetDb))  | 
                                                        |
| 791 | -      throw new \InvalidArgumentException("\$createTargetDb must be a bool."); | 
                                                        |
| 792 | - elseif ($createTargetDb)  | 
                                                        |
| 793 | - $body["create_target"] = $createTargetDb;  | 
                                                        |
| 813 | +    if (!is_bool($createTargetDb)) { | 
                                                        |
| 814 | +          throw new \InvalidArgumentException("\$createTargetDb must be a bool."); | 
                                                        |
| 815 | +    } elseif ($createTargetDb) { | 
                                                        |
| 816 | + $body["create_target"] = $createTargetDb;  | 
                                                        |
| 817 | + }  | 
                                                        |
| 794 | 818 | |
| 795 | 819 |      if (!empty($filter)) { | 
                                                        
| 796 | - if (is_string($filter)) // filter option  | 
                                                        |
| 820 | +      if (is_string($filter)) { | 
                                                        |
| 821 | + // filter option  | 
                                                        |
| 797 | 822 | $body["filter"] = $filter;  | 
                                                        
| 798 | - elseif (is_array($filter)) // doc_ids option  | 
                                                        |
| 823 | +      } elseif (is_array($filter)) { | 
                                                        |
| 824 | + // doc_ids option  | 
                                                        |
| 799 | 825 | $body["doc_ids"] = array_values($filter);  | 
                                                        
| 800 | - else  | 
                                                        |
| 801 | -        throw new \InvalidArgumentException("\$filter must be a string or an array."); | 
                                                        |
| 826 | +      } else { | 
                                                        |
| 827 | +              throw new \InvalidArgumentException("\$filter must be a string or an array."); | 
                                                        |
| 828 | + }  | 
                                                        |
| 802 | 829 | }  | 
                                                        
| 803 | 830 | |
| 804 | 831 | // queryParams option  | 
                                                        
| 805 | 832 |      if (!is_null($opts)) { | 
                                                        
| 806 | - if ($opts instanceof Opt\ViewQueryOpts)  | 
                                                        |
| 807 | - $body["query_params"] = get_object_vars($opts);  | 
                                                        |
| 808 | - else  | 
                                                        |
| 809 | -        throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); | 
                                                        |
| 833 | +      if ($opts instanceof Opt\ViewQueryOpts) { | 
                                                        |
| 834 | + $body["query_params"] = get_object_vars($opts);  | 
                                                        |
| 835 | +      } else { | 
                                                        |
| 836 | +              throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); | 
                                                        |
| 837 | + }  | 
                                                        |
| 810 | 838 | }  | 
                                                        
| 811 | 839 | |
| 812 | 840 | $request = new Request(Request::POST_METHOD, "/_replicate");  | 
                                                        
@@ -823,8 +851,9 @@ discard block  | 
                                                    ||
| 823 | 851 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication  | 
                                                        
| 824 | 852 | */  | 
                                                        
| 825 | 853 |    public function stopReplication($replicationId) { | 
                                                        
| 826 | - if (is_null($replicationId))  | 
                                                        |
| 827 | -      throw new \InvalidArgumentException("You must provide a replication id."); | 
                                                        |
| 854 | +    if (is_null($replicationId)) { | 
                                                        |
| 855 | +          throw new \InvalidArgumentException("You must provide a replication id."); | 
                                                        |
| 856 | + }  | 
                                                        |
| 828 | 857 | |
| 829 | 858 | $body["replication_id"] = $replicationId;  | 
                                                        
| 830 | 859 | $body["cancel"] = TRUE;  | 
                                                        
@@ -873,15 +902,16 @@ discard block  | 
                                                    ||
| 873 | 902 | * @see http://docs.couchdb.org/en/latest/api/database/bulk-api.html#post--db-_all_docs  | 
                                                        
| 874 | 903 | */  | 
                                                        
| 875 | 904 |    public function queryAllDocs($dbName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, IChunkHook $chunkHook = NULL) { | 
                                                        
| 876 | - if (is_null($keys))  | 
                                                        |
| 877 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs");  | 
                                                        |
| 878 | -    else { | 
                                                        |
| 905 | +    if (is_null($keys)) { | 
                                                        |
| 906 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs");  | 
                                                        |
| 907 | +    } else { | 
                                                        |
| 879 | 908 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_all_docs");  | 
                                                        
| 880 | 909 | $request->setBody(json_encode(['keys' => $keys]));  | 
                                                        
| 881 | 910 | }  | 
                                                        
| 882 | 911 | |
| 883 | - if (isset($opts))  | 
                                                        |
| 884 | - $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 912 | +    if (isset($opts)) { | 
                                                        |
| 913 | + $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        |
| 914 | + }  | 
                                                        |
| 885 | 915 | |
| 886 | 916 | $result = $this->send($request, $chunkHook)->getBodyAsArray();  | 
                                                        
| 887 | 917 | |
@@ -910,12 +940,13 @@ discard block  | 
                                                    ||
| 910 | 940 |    public function queryView($dbName, $designDocName, $viewName, array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, IChunkHook $chunkHook = NULL) { | 
                                                        
| 911 | 941 | $this->validateAndEncodeDocId($designDocName);  | 
                                                        
| 912 | 942 | |
| 913 | - if (empty($viewName))  | 
                                                        |
| 914 | -      throw new \InvalidArgumentException("You must provide a valid \$viewName."); | 
                                                        |
| 943 | +    if (empty($viewName)) { | 
                                                        |
| 944 | +          throw new \InvalidArgumentException("You must provide a valid \$viewName."); | 
                                                        |
| 945 | + }  | 
                                                        |
| 915 | 946 | |
| 916 | - if (empty($keys))  | 
                                                        |
| 917 | - $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName);  | 
                                                        |
| 918 | -    else { | 
                                                        |
| 947 | +    if (empty($keys)) { | 
                                                        |
| 948 | + $request = new Request(Request::GET_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName);  | 
                                                        |
| 949 | +    } else { | 
                                                        |
| 919 | 950 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_design/".$designDocName."/_view/".$viewName);  | 
                                                        
| 920 | 951 | $request->setBody(json_encode(['keys' => $keys]));  | 
                                                        
| 921 | 952 | }  | 
                                                        
@@ -926,14 +957,15 @@ discard block  | 
                                                    ||
| 926 | 957 |      if (isset($opts)) { | 
                                                        
| 927 | 958 | $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        
| 928 | 959 | $includeMissingKeys = $opts->issetIncludeMissingKeys();  | 
                                                        
| 960 | +    } else { | 
                                                        |
| 961 | + $includeMissingKeys = FALSE;  | 
                                                        |
| 929 | 962 | }  | 
                                                        
| 930 | - else  | 
                                                        |
| 931 | - $includeMissingKeys = FALSE;  | 
                                                        |
| 932 | 963 | |
| 933 | 964 | $result = $this->send($request, $chunkHook)->getBodyAsArray();  | 
                                                        
| 934 | 965 | |
| 935 | - if ($includeMissingKeys)  | 
                                                        |
| 936 | - $this->addMissingRows($keys, $result['rows']);  | 
                                                        |
| 966 | +    if ($includeMissingKeys) { | 
                                                        |
| 967 | + $this->addMissingRows($keys, $result['rows']);  | 
                                                        |
| 968 | + }  | 
                                                        |
| 937 | 969 | |
| 938 | 970 | return new Result\QueryResult($result);  | 
                                                        
| 939 | 971 | }  | 
                                                        
@@ -960,30 +992,33 @@ discard block  | 
                                                    ||
| 960 | 992 |      $handler = new Handler\ViewHandler('temp'); | 
                                                        
| 961 | 993 | $handler->language = $language;  | 
                                                        
| 962 | 994 | $handler->mapFn = $mapFn;  | 
                                                        
| 963 | - if (!empty($reduce))  | 
                                                        |
| 964 | - $handler->reduceFn = $reduceFn;  | 
                                                        |
| 995 | +    if (!empty($reduce)) { | 
                                                        |
| 996 | + $handler->reduceFn = $reduceFn;  | 
                                                        |
| 997 | + }  | 
                                                        |
| 965 | 998 | |
| 966 | 999 | $request = new Request(Request::POST_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_temp_view");  | 
                                                        
| 967 | 1000 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");  | 
                                                        
| 968 | 1001 | |
| 969 | 1002 | $array = $handler->asArray();  | 
                                                        
| 970 | 1003 | |
| 971 | - if (!empty($keys))  | 
                                                        |
| 972 | - $array['keys'] = $keys;  | 
                                                        |
| 1004 | +    if (!empty($keys)) { | 
                                                        |
| 1005 | + $array['keys'] = $keys;  | 
                                                        |
| 1006 | + }  | 
                                                        |
| 973 | 1007 | |
| 974 | 1008 | $request->setBody(json_encode($array));  | 
                                                        
| 975 | 1009 | |
| 976 | 1010 |      if (isset($opts)) { | 
                                                        
| 977 | 1011 | $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        
| 978 | 1012 | $includeMissingKeys = $opts->issetIncludeMissingKeys();  | 
                                                        
| 1013 | +    } else { | 
                                                        |
| 1014 | + $includeMissingKeys = FALSE;  | 
                                                        |
| 979 | 1015 | }  | 
                                                        
| 980 | - else  | 
                                                        |
| 981 | - $includeMissingKeys = FALSE;  | 
                                                        |
| 982 | 1016 | |
| 983 | 1017 | $result = $this->send($request, $chunkHook)->getBodyAsArray();  | 
                                                        
| 984 | 1018 | |
| 985 | - if ($includeMissingKeys)  | 
                                                        |
| 986 | - $this->addMissingRows($keys, $result['rows']);  | 
                                                        |
| 1019 | +    if ($includeMissingKeys) { | 
                                                        |
| 1020 | + $this->addMissingRows($keys, $result['rows']);  | 
                                                        |
| 1021 | + }  | 
                                                        |
| 987 | 1022 | |
| 988 | 1023 | return new Result\QueryResult($result);  | 
                                                        
| 989 | 1024 | }  | 
                                                        
@@ -1042,8 +1077,9 @@ discard block  | 
                                                    ||
| 1042 | 1077 | * @see http://docs.couchdb.org/en/latest/api/database/misc.html#put--db-_revs_limit  | 
                                                        
| 1043 | 1078 | */  | 
                                                        
| 1044 | 1079 |    public function setRevsLimit($dbName, $revsLimit = self::REVS_LIMIT) { | 
                                                        
| 1045 | - if (!is_int($revsLimit) || ($revsLimit <= 0))  | 
                                                        |
| 1046 | -      throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); | 
                                                        |
| 1080 | +    if (!is_int($revsLimit) || ($revsLimit <= 0)) { | 
                                                        |
| 1081 | +          throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); | 
                                                        |
| 1082 | + }  | 
                                                        |
| 1047 | 1083 | |
| 1048 | 1084 | $request = new Request(Request::PUT_METHOD, "/".rawurlencode($this->prefix.$dbName)."/_revs_limit");  | 
                                                        
| 1049 | 1085 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");  | 
                                                        
@@ -1102,16 +1138,17 @@ discard block  | 
                                                    ||
| 1102 | 1138 | $request = new Request(Request::GET_METHOD, $requestPath);  | 
                                                        
| 1103 | 1139 | |
| 1104 | 1140 | // Retrieves the specific revision of the document.  | 
                                                        
| 1105 | - if (!empty($rev))  | 
                                                        |
| 1106 | -      $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1141 | +    if (!empty($rev)) { | 
                                                        |
| 1142 | +          $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1143 | + }  | 
                                                        |
| 1107 | 1144 | |
| 1108 | 1145 | // If there are any options, add them to the request.  | 
                                                        
| 1109 | 1146 |      if (isset($opts)) { | 
                                                        
| 1110 | 1147 | $request->setMultipleQueryParamsAtOnce($opts->asArray());  | 
                                                        
| 1111 | 1148 | $ignoreClass = $opts->issetIgnoreClass();  | 
                                                        
| 1149 | +    } else { | 
                                                        |
| 1150 | + $ignoreClass = FALSE;  | 
                                                        |
| 1112 | 1151 | }  | 
                                                        
| 1113 | - else  | 
                                                        |
| 1114 | - $ignoreClass = FALSE;  | 
                                                        |
| 1115 | 1152 | |
| 1116 | 1153 | $response = $this->send($request);  | 
                                                        
| 1117 | 1154 | $body = $response->getBodyAsArray();  | 
                                                        
@@ -1123,18 +1160,18 @@ discard block  | 
                                                    ||
| 1123 | 1160 |      if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc. | 
                                                        
| 1124 | 1161 | $class = "\\".$body['class'];  | 
                                                        
| 1125 | 1162 | $doc = new $class;  | 
                                                        
| 1163 | +    } elseif ($path == self::DESIGN_DOC_PATH) { | 
                                                        |
| 1164 | + $doc = new Doc\DesignDoc;  | 
                                                        |
| 1165 | +    } else { | 
                                                        |
| 1166 | + $doc = NULL;  | 
                                                        |
| 1126 | 1167 | }  | 
                                                        
| 1127 | - elseif ($path == self::DESIGN_DOC_PATH)  | 
                                                        |
| 1128 | - $doc = new Doc\DesignDoc;  | 
                                                        |
| 1129 | - else  | 
                                                        |
| 1130 | - $doc = NULL;  | 
                                                        |
| 1131 | 1168 | |
| 1132 | 1169 |      if (is_object($doc)) { | 
                                                        
| 1133 | 1170 | $doc->assignArray($body);  | 
                                                        
| 1134 | 1171 | return $doc;  | 
                                                        
| 1172 | +    } else { | 
                                                        |
| 1173 | + return $response;  | 
                                                        |
| 1135 | 1174 | }  | 
                                                        
| 1136 | - else  | 
                                                        |
| 1137 | - return $response;  | 
                                                        |
| 1138 | 1175 | }  | 
                                                        
| 1139 | 1176 | |
| 1140 | 1177 | |
@@ -1154,8 +1191,9 @@ discard block  | 
                                                    ||
| 1154 | 1191 |    public function saveDoc($dbName, Doc\IDoc $doc, $batchMode = FALSE) { | 
                                                        
| 1155 | 1192 | // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc  | 
                                                        
| 1156 | 1193 | // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids.  | 
                                                        
| 1157 | - if (!$doc->issetId())  | 
                                                        |
| 1158 | - $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));  | 
                                                        |
| 1194 | +    if (!$doc->issetId()) { | 
                                                        |
| 1195 | + $doc->setId(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING));  | 
                                                        |
| 1196 | + }  | 
                                                        |
| 1159 | 1197 | |
| 1160 | 1198 | $this->setDocInfo($doc);  | 
                                                        
| 1161 | 1199 | |
@@ -1169,8 +1207,9 @@ discard block  | 
                                                    ||
| 1169 | 1207 | $request->setBody($doc->asJson());  | 
                                                        
| 1170 | 1208 | |
| 1171 | 1209 | // Enables batch mode.  | 
                                                        
| 1172 | - if ($batchMode)  | 
                                                        |
| 1173 | -      $request->setQueryParam("batch", "ok"); | 
                                                        |
| 1210 | +    if ($batchMode) { | 
                                                        |
| 1211 | +          $request->setQueryParam("batch", "ok"); | 
                                                        |
| 1212 | + }  | 
                                                        |
| 1174 | 1213 | |
| 1175 | 1214 | $this->send($request);  | 
                                                        
| 1176 | 1215 | }  | 
                                                        
@@ -1223,10 +1262,11 @@ discard block  | 
                                                    ||
| 1223 | 1262 | // This request uses the special method COPY.  | 
                                                        
| 1224 | 1263 | $request = new Request(Request::COPY_METHOD, $path);  | 
                                                        
| 1225 | 1264 | |
| 1226 | - if (empty($rev))  | 
                                                        |
| 1227 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);  | 
                                                        |
| 1228 | - else  | 
                                                        |
| 1229 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);  | 
                                                        |
| 1265 | +    if (empty($rev)) { | 
                                                        |
| 1266 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId);  | 
                                                        |
| 1267 | +    } else { | 
                                                        |
| 1268 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev);  | 
                                                        |
| 1269 | + }  | 
                                                        |
| 1230 | 1270 | |
| 1231 | 1271 | $this->send($request);  | 
                                                        
| 1232 | 1272 | }  | 
                                                        
@@ -1255,8 +1295,9 @@ discard block  | 
                                                    ||
| 1255 | 1295 | $request = new Request(Request::POST_METHOD, $path);  | 
                                                        
| 1256 | 1296 | |
| 1257 | 1297 | $purge = [];  | 
                                                        
| 1258 | - foreach ($refs as $ref)  | 
                                                        |
| 1259 | - $purge[] = $ref->asArray();  | 
                                                        |
| 1298 | +    foreach ($refs as $ref) { | 
                                                        |
| 1299 | + $purge[] = $ref->asArray();  | 
                                                        |
| 1300 | + }  | 
                                                        |
| 1260 | 1301 | |
| 1261 | 1302 | $request->setBody(json_encode($purge));  | 
                                                        
| 1262 | 1303 | |
@@ -1288,26 +1329,30 @@ discard block  | 
                                                    ||
| 1288 | 1329 | * @see http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API  | 
                                                        
| 1289 | 1330 | */  | 
                                                        
| 1290 | 1331 |    public function performBulkOperations($dbName, array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) { | 
                                                        
| 1291 | - if (count($docs) == 0)  | 
                                                        |
| 1292 | -      throw new \InvalidArgumentException("The \$docs array cannot be empty."); | 
                                                        |
| 1293 | - else  | 
                                                        |
| 1294 | - $operations = [];  | 
                                                        |
| 1332 | +    if (count($docs) == 0) { | 
                                                        |
| 1333 | +          throw new \InvalidArgumentException("The \$docs array cannot be empty."); | 
                                                        |
| 1334 | +    } else { | 
                                                        |
| 1335 | + $operations = [];  | 
                                                        |
| 1336 | + }  | 
                                                        |
| 1295 | 1337 | |
| 1296 | 1338 | $path = "/".rawurlencode($this->prefix.$dbName)."/_bulk_docs";  | 
                                                        
| 1297 | 1339 | |
| 1298 | 1340 | $request = new Request(Request::POST_METHOD, $path);  | 
                                                        
| 1299 | 1341 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json");  | 
                                                        
| 1300 | 1342 | |
| 1301 | - if ($fullCommit)  | 
                                                        |
| 1302 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");  | 
                                                        |
| 1303 | - else  | 
                                                        |
| 1304 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");  | 
                                                        |
| 1343 | +    if ($fullCommit) { | 
                                                        |
| 1344 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit");  | 
                                                        |
| 1345 | +    } else { | 
                                                        |
| 1346 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit");  | 
                                                        |
| 1347 | + }  | 
                                                        |
| 1305 | 1348 | |
| 1306 | - if ($allOrNothing)  | 
                                                        |
| 1307 | - $operations['all_or_nothing'] = 'true';  | 
                                                        |
| 1349 | +    if ($allOrNothing) { | 
                                                        |
| 1350 | + $operations['all_or_nothing'] = 'true';  | 
                                                        |
| 1351 | + }  | 
                                                        |
| 1308 | 1352 | |
| 1309 | - if (!$newEdits)  | 
                                                        |
| 1310 | - $operations['new_edits'] = 'false';  | 
                                                        |
| 1353 | +    if (!$newEdits) { | 
                                                        |
| 1354 | + $operations['new_edits'] = 'false';  | 
                                                        |
| 1355 | + }  | 
                                                        |
| 1311 | 1356 | |
| 1312 | 1357 |      foreach ($docs as $doc) { | 
                                                        
| 1313 | 1358 | $this->setDocInfo($doc);  | 
                                                        
@@ -1345,8 +1390,9 @@ discard block  | 
                                                    ||
| 1345 | 1390 | $request = new Request(Request::HEAD_METHOD, $path);  | 
                                                        
| 1346 | 1391 | |
| 1347 | 1392 | // In case we want retrieve a specific document revision.  | 
                                                        
| 1348 | - if (!empty($rev))  | 
                                                        |
| 1349 | -      $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1393 | +    if (!empty($rev)) { | 
                                                        |
| 1394 | +          $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1395 | + }  | 
                                                        |
| 1350 | 1396 | |
| 1351 | 1397 | return $this->send($request)->getHeaderAsArray();  | 
                                                        
| 1352 | 1398 | }  | 
                                                        
@@ -1372,8 +1418,9 @@ discard block  | 
                                                    ||
| 1372 | 1418 | $request = new Request(Request::GET_METHOD, $path);  | 
                                                        
| 1373 | 1419 | |
| 1374 | 1420 | // In case we want retrieve a specific document revision.  | 
                                                        
| 1375 | - if (!empty($rev))  | 
                                                        |
| 1376 | -      $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1421 | +    if (!empty($rev)) { | 
                                                        |
| 1422 | +          $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1423 | + }  | 
                                                        |
| 1377 | 1424 | |
| 1378 | 1425 | return $this->send($request)->getBody();  | 
                                                        
| 1379 | 1426 | }  | 
                                                        
@@ -1402,8 +1449,9 @@ discard block  | 
                                                    ||
| 1402 | 1449 | $request->setBody(base64_encode($attachment->getData()));  | 
                                                        
| 1403 | 1450 | |
| 1404 | 1451 | // In case of adding or updating an existence document.  | 
                                                        
| 1405 | - if (!empty($rev))  | 
                                                        |
| 1406 | -      $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1452 | +    if (!empty($rev)) { | 
                                                        |
| 1453 | +          $request->setQueryParam("rev", (string)$rev); | 
                                                        |
| 1454 | + }  | 
                                                        |
| 1407 | 1455 | |
| 1408 | 1456 | return $this->send($request);  | 
                                                        
| 1409 | 1457 | }  | 
                                                        
@@ -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 | }  |