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

Operations   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 55
ccs 16
cts 19
cp 0.8421
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A perform() 0 13 4
A getData() 0 4 1
A getInvalidFields() 0 4 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