Completed
Push — master ( a30571...7a668c )
by James Ekow Abaka
02:45
created

Operations::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
namespace ntentan\nibii;
4
5
class Operations
6
{
7
8
    private $wrapper;
9
10
    /**
11
     *
12
     * @var \ntentan\nibii\DriverAdapter
13
     */
14
    private $adapter;
15
    private $queryOperations;
16
    private $dataOperations;
17
    private $queryOperationMethods = [
18
        'fetch', 'fetchFirst', 'filter', 'query', 'fields',
19
        'cover', 'limit', 'offset', 'filterBy', 'sortBy',
20
        'delete', 'count', 'update', 'with'
21
    ];
22
    private $dataOperationMethods = [
23
        'save', 'validate'
24
    ];
25
26 34
    public function __construct(RecordWrapper $wrapper, $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...
27
    {
28 34
        $this->wrapper = $wrapper;
29 34
        $this->adapter = $wrapper->getAdapter();
30 34
        $driver = ORMContext::getInstance()->getDbContext()->getDriver();
31 34
        $this->dataOperations = new DataOperations($wrapper, $driver);
32 34
        $this->queryOperations = new QueryOperations($wrapper, $this->dataOperations, $driver);
33 34
    }
34
35 34
    public function perform($name, $arguments)
36
    {
37
        //@todo Think of using a hash here in future
38 34
        if (array_search($name, $this->queryOperationMethods) !== false) {
39 30
            return call_user_func_array([$this->queryOperations, "do$name"], $arguments);
40 18
        } else if (array_search($name, $this->dataOperationMethods) !== false) {
41 10
            return call_user_func_array([$this->dataOperations, "do$name"], $arguments);
42 10
        } else if ($this->queryOperations->initDynamicMethod($name)) {
43 10
            return $this->queryOperations->runDynamicMethod($arguments);
44
        } else {
45
            throw new NibiiException("Method {$name} not found");
46
        }
47
    }
48
49
    public function getData()
50
    {
51
        return $this->dataOperations->getData();
52
    }
53
54 10
    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...
55
    {
56 10
        return $this->dataOperations->getInvalidFields();
57
    }
58
59
}
60