AddFunCmd   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A execute() 0 5 1
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
}