AddFunCmd::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/**
4
 * @file AddFunCmd.php
5
 * @brief This file contains the AddFunCmd class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
namespace EoC\Command;
12
13
14
/**
15
 * @brief Evaluates the function received from CouchDB, checks for syntax errors and finally stores the function
16
 * implementation, so CouchDB can call it later.
17
 * @details When creating a view, the view server gets sent the view function for evaluation. The view server should
18
 * parse/compile/evaluate the function he receives to make it callable later. If this fails, the view server returns
19
 * an error. CouchDB might store several functions before sending in any actual documents.\n\n
20
 * The argument provided by CouchDB has the following structure:
21
 @code
22
   Array
23
   (
24
       [0] => function($doc) use ($emit) {
25
                if ($doc->contributorName == "Filippo Fadda")
26
                  $emit($doc->contributorName, $doc->idItem);
27
              };
28
   )
29
 @endcode
30
 */
31
final class AddFunCmd extends AbstractCmd {
32
  use CmdTrait;
33
34
35
  public static function getName() {
36
    return "add_fun";
37
  }
38
39
40
  public function execute() {
41
    $fn = reset($this->args);
42
    $this->server->addFunc($fn);
43
    $this->server->writeln("true");
44
  }
45
46
}