Completed
Push — master ( 0864bb...f3fc5f )
by Fede
08:54 queued 07:04
created

StdEnvironment   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 96.77%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 61
ccs 30
cts 31
cp 0.9677
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 58 1
1
<?php
2
3
namespace LisPhp\Environment;
4
5
class StdEnvironment extends Environment
6
{
7 24
    public function __construct()
8
    {
9
        $this->container += [
10
            '+' => function () {
11 9
                return array_sum(func_get_arg(0));
12 24
            },
13
            '-' => function () {
14 6
                list($first, $second) = func_get_arg(0); // array [5, 3]
15 6
                return $first - $second;
16 24
            },
17
            '*' => function () {
18 6
                return array_product(func_get_arg(0));
19 24
            },
20
            '/' => function () {
21 3
                return func_get_arg(0)[0] / func_get_arg(0)[1];
22 24
            },
23
            '>' => function () {
24 9
                return func_get_arg(0)[0] > func_get_arg(0)[1];
25 24
            },
26
            '>=' => function () {
27
                return func_get_arg(0)[0] >= func_get_arg(0)[1];
28 24
            },
29
            '<' => function () {
30 3
                return func_get_arg(0)[0] < func_get_arg(0)[1];
31 24
            },
32
            '<=' => function () {
33
                return func_get_arg(0)[0] <= func_get_arg(0)[1];
34 24
            },
35
            '=' => function () {
36
                return func_get_arg(0)[0] == func_get_arg(0)[1];
37 24
            },
38
            'abs' => function () {
39
                return abs(func_get_arg(0));
40 24
            },
41
            'not' => function () {
42
                return !func_get_arg(0);
43 24
            },
44
            'first' => function () {
45
                return func_get_arg(0)[0][0];
46 24
            },
47
            'list' => function () {
48
                return func_get_args()[0];
49 24
            },
50
            'eq?' => function () {
51
                return func_get_arg(0)[0] == func_get_arg(0)[1];
52 24
            },
53
            'number?' => function () {
54
                return is_numeric(func_get_arg(0));
55 24
            },
56
            'quote' => function () {
57 6
                return implode(' ', func_get_arg(0));
58 24
            },
59 24
            'define' => function () {
60 3
                list($name, $value) = func_get_arg(0);
61 3
                $this[$name] = $value;
62 24
            },
63
        ];
64 24
    }
65
}
66