basicOp()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 5
nop 3
dl 0
loc 11
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/*
3
Your task is to create a function that does four basic mathematical operations.
4
5
The function should take three arguments - operation(string/char), value1(number), value2(number).
6
The function should return result of numbers after applying the chosen operation.
7
Examples
8
9
basicOp('+', 4, 7)         // Output: 11
10
basicOp('-', 15, 18)       // Output: -3
11
basicOp('*', 5, 5)         // Output: 25
12
basicOp('/', 49, 7)        // Output: 7
13
*/
14
15
function basicOp($operator, $value1, $value2)
16
{
17
    switch ($operator) {
18
    case "+":
19
        return $value1 + $value2;
20
    case "-":
21
        return $value1 - $value2;
22
    case "*":
23
        return $value1 * $value2;
24
    case "/":
25
        return $value1 / $value2;
26
    }
27
}
28