Interpreter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 10 2
A getMethodCalls() 0 6 1
1
<?php
2
3
namespace EloquentJs\Query;
4
5
use Illuminate\Http\Request;
6
use InvalidArgumentException;
7
8
class Interpreter
9
{
10
    /**
11
     * Read an EloquentJs `Query` from the given request.
12
     *
13
     * @param Request $request
14
     * @return Query
15
     */
16
    public function parse(Request $request)
17
    {
18
        $calls = json_decode($request->input('query', '[]'));
19
20
        if ($calls === null) {
21
            throw new InvalidArgumentException('The query could not be decoded: '.json_last_error_msg());
22
        }
23
24
        return new Query($this->getMethodCalls($calls));
25
    }
26
27
    /**
28
     * Convert plain array of [methodName, [methodArgs...]] to MethodCall instances.
29
     *
30
     * @param array $calls
31
     * @return array
32
     */
33
    protected function getMethodCalls(array $calls)
34
    {
35
        return array_map(function($call) {
36
            return new MethodCall($call[0], $call[1]);
37
        }, $calls);
38
    }
39
}
40