RereduceCmd::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @file RereduceCmd.php
5
 * @brief This file contains the RereduceCmd class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
namespace EoC\Command;
12
13
14
/**
15
 * @brief The map command (MapCmd) generates a set of key/value pairs, which can then optionally be reduced to single
16
 * value or to a group of values by the reduce command (ReduceCmd). The rereduce command (RereduceCmd) try to call your
17
 * reduce function recursively on its own input.
18
 * @details The reduce step primarily involves working with keys and values, not document IDs. Either a single computed
19
 * reduction of all values will be produced, or reductions of values grouped by keys, will ultimately be produced.
20
 * Grouping is controlled by parameters passed to your view, not by the reduce function itself.\n\n
21
 * The argument provided by CouchDB has the following structure:
22
 @code
23
   Array
24
   (
25
       [0] => Array
26
       (
27
           [0] => function($keys, $values, $rereduce) {
28
                    if ($rereduce)
29
                      return array_sum($values);
30
                    else
31
                      return sizeof($values);
32
                  };
33
       )
34
       [1] => Array
35
       (
36
           [0] => 48360
37
           [1] => 48311
38
           [2] => 48324
39
       )
40
   )
41
 @endcode
42
 */
43
final class RereduceCmd extends AbstractCmd {
44
  use CmdTrait;
45
46
47
  public static function getName() {
48
    return "rereduce";
49
  }
50
51
52
  public function execute() {
53
    // Extracts functions and values from the arguments array.
54
    @list($funcs, $values) = $this->args;
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
55
56
    $this->server->reduce($funcs, NULL, $values, TRUE);
57
  }
58
59
}