Passed
Push — master ( 310acb...1a0150 )
by Scott
02:48
created

Quasiquote::run()   C

Complexity

Conditions 9
Paths 4

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 17
cts 17
cp 1
rs 5.3563
c 0
b 0
f 0
cc 9
eloc 17
nc 4
nop 1
crap 9
1
<?php
2
namespace Desmond\functions\special;
3
use Desmond\functions\DesmondSpecialFunction;
4
use Desmond\data_types\ListType;
5
6
class Quasiquote implements DesmondSpecialFunction
7
{
8 8
    public function run(array $args)
9
    {
10 8
        $arg = $args[0];
11 8
        $isList = $arg instanceof ListType;
12 8
        if ($isList && !empty($arg->value())) {
13 6
            $list = $arg;
14 6
            foreach ($list->value() as $index => $element) {
15 6
                if ($element->value() == 'unquote') {
16 2
                    $newValue = $this->eval->getReturn($list->rest()[0]);
0 ignored issues
show
Bug introduced by
The property eval does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17 2
                    $list = $newValue;
18
                }
19 6
                else if ($element instanceof ListType && !empty($element->value())) {
20 2
                    if ($element->first()->value() == 'unquote') {
21 1
                        $newValue = $this->eval->getReturn($element->rest()[0]);
22 6
                        $list->set($newValue, $index);
23
                    }
24
                }
25
            }
26
        }
27 8
        $quote = new Quote();
28 8
        return isset($list)
29 6
            ? $quote->run([$list], $this->function, $this->currentEnv, $this->eval)
0 ignored issues
show
Bug introduced by
The property function does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property currentEnv does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Unused Code introduced by
The call to Quote::run() has too many arguments starting with $this->function.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30 8
            : $quote->run($args, $this->function, $this->currentEnv, $this->eval);
0 ignored issues
show
Unused Code introduced by
The call to Quote::run() has too many arguments starting with $this->function.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
31
    }
32
}
33