Code Duplication    Length = 10-21 lines in 2 locations

src/EoC/Command/MapDocCmd.php 1 location

@@ 64-84 (lines=21) @@
61
62
    $result = []; // Every time we map a document against all the registered functions we must reset the result.
63
64
    foreach ($this->server->getFuncs() as $fn) {
65
      $map = []; // Every time we map a document against a function we must reset the map.
66
67
      // Here we call the closure function stored in the view. The $closure variable contains the function implementation
68
      // provided by the user. You can have multiple views in a design document and for every single view you can have
69
      // only one map function.
70
      // The closure must be declared like:
71
      //
72
      //     function($doc) use ($emit) { ... };
73
      //
74
      // This technique let you use the syntax '$emit($key, $value);' to emit your record. The function doesn't return
75
      // any value. You don't need to include any files since the closure's code is executed inside this method.
76
      eval("\$closure = ".$fn);
77
78
      if (is_callable($closure)) {
79
        call_user_func($closure, $doc);
80
        $result[] = $map;
81
      }
82
      else
83
        throw new \BadFunctionCallException("The map function is not callable.");
84
    }
85
86
    // Sends mappings to CouchDB.
87
    $this->server->writeln(json_encode($result));

src/EoC/Server.php 1 location

@@ 185-194 (lines=10) @@
182
    $reductions = [];
183
184
    // Executes the reductions.
185
    foreach ($funcs as $fn) {
186
      $this->monolog->addDebug($fn);
187
188
      eval("\$closure = ".$fn);
189
190
      if (is_callable($closure))
191
        $reductions[] = call_user_func($closure, $keys, $values, $rereduce);
192
      else
193
        throw new \BadFunctionCallException("The reduce function is not callable.");
194
    }
195
196
    // Sends mappings to CouchDB.
197
    $this->writeln("[true,".json_encode($reductions)."]");