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

StdEnvironment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 30
cts 31
cp 0.9677
rs 9.639
c 0
b 0
f 0
cc 1
eloc 38
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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