Completed
Push — master ( 7fd5f6...af8ac7 )
by James Ekow Abaka
01:40
created

Operations::perform()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 7.9062

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 3
cts 8
cp 0.375
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 2
crap 7.9062
1
<?php
2
3
namespace ntentan\nibii;
4
5
use ntentan\panie\Container;
6
7
class Operations {
8
9
    private $wrapper;
10
11
    /**
12
     *
13
     * @var \ntentan\nibii\DriverAdapter
14
     */
15
    private $adapter;
16
    private $queryOperations;
17
    private $dataOperations;
18
    private $queryOperationMethods = [
19
        'fetch', 'fetchFirst', 'filter', 'query', 'fields',
20
        'cover', 'limit', 'offset', 'filterBy', 'sortBy',
21
        'delete', 'count', 'update', 'with'
22
    ];
23
    private $dataOperationMethods = [
24
        'save', 'validate'
25
    ];
26
27 1
    public function __construct(Container $container, RecordWrapper $wrapper, DriverAdapter $adapter, $table) {
0 ignored issues
show
Unused Code introduced by
The parameter $table is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28 1
        $this->wrapper = $wrapper;
29 1
        $this->adapter = $adapter;
30 1
        $this->dataOperations = $container->resolve(DataOperations::class, ['adapter' => $adapter]);
31 1
        $this->queryOperations = $container->resolve(QueryOperations::class, ['dataOperations' => $this->dataOperations, 'adapter' => $adapter]);
32 1
    }
33
34 1
    public function perform($name, $arguments) {
35
        //@todo Think of using a hash here in future
36 1
        if (array_search($name, $this->queryOperationMethods) !== false) {
37 1
            return call_user_func_array([$this->queryOperations, "do$name"], $arguments);
38
        } else if (array_search($name, $this->dataOperationMethods) !== false) {
39
            return call_user_func_array([$this->dataOperations, "do$name"], $arguments);
40
        } else if ($this->queryOperations->initDynamicMethod($name)) {
41
            return $this->queryOperations->runDynamicMethod($arguments);
42
        } else {
43
            throw new NibiiException("Method {$name} not found");
44
        }
45
    }
46
47
    public function getData() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
48
        return $this->dataOperations->getData();
49
    }
50
51
    public function getInvalidFields() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
52
        return $this->dataOperations->getInvalidFields();
53
    }
54
55
}
56