MCPcopy Create free account
hub / github.com/apache/thrift / calculate

Method calculate

tutorial/php/PhpServer.php:67–101  ·  view source on GitHub ↗
($logid, \tutorial\Work $w)

Source from the content-addressed store, hash-verified

65 }
66
67 public function calculate($logid, \tutorial\Work $w) {
68 error_log("calculate({$logid}, {{$w->op}, {$w->num1}, {$w->num2}})");
69 switch ($w->op) {
70 case \tutorial\Operation::ADD:
71 $val = $w->num1 + $w->num2;
72 break;
73 case \tutorial\Operation::SUBTRACT:
74 $val = $w->num1 - $w->num2;
75 break;
76 case \tutorial\Operation::MULTIPLY:
77 $val = $w->num1 * $w->num2;
78 break;
79 case \tutorial\Operation::DIVIDE:
80 if ($w->num2 == 0) {
81 $io = new \tutorial\InvalidOperation();
82 $io->whatOp = $w->op;
83 $io->why = "Cannot divide by 0";
84 throw $io;
85 }
86 $val = $w->num1 / $w->num2;
87 break;
88 default:
89 $io = new \tutorial\InvalidOperation();
90 $io->whatOp = $w->op;
91 $io->why = "Invalid Operation";
92 throw $io;
93 }
94
95 $log = new \shared\SharedStruct();
96 $log->key = $logid;
97 $log->value = (string)$val;
98 $this->log[$logid] = $log;
99
100 return $val;
101 }
102
103 public function getStruct($key) {
104 error_log("getStruct({$key})");

Callers 1

PhpClient.phpFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected