Completed
Push — master ( ffb215...f806ab )
by Anton
11s
created

AbstractCrud   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 163
ccs 16
cts 32
cp 0.5
rs 10
c 2
b 0
f 1
wmc 14
lcom 0
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 9 2
getPrimaryKey() 0 1 ?
A readOne() 0 4 1
A readSet() 0 4 1
A createOne() 0 4 1
A createSet() 0 4 1
A updateOne() 0 4 1
A updateSet() 0 4 1
A deleteOne() 0 4 1
A deleteSet() 0 4 1
B getMethods() 0 28 4
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link https://github.com/bluzphp/framework
7
 */
8
9
/**
10
 * @namespace
11
 */
12
namespace Bluz\Crud;
13
14
use Bluz\Application\Exception\NotImplementedException;
15
16
/**
17
 * Crud
18
 *
19
 * @package  Bluz\Crud
20
 * @author   Anton Shevchuk
21
 * @link     https://github.com/bluzphp/framework/wiki/Crud
22
 */
23
abstract class AbstractCrud
24
{
25
    /**
26
     * Default limit for READ SET of elements
27
     */
28
    const DEFAULT_LIMIT = 10;
29
30
    /**
31
     * Get CRUD Instance
32
     *
33
     * @return static
34
     */
35
    public static function getInstance()
36
    {
37
        static $instance;
38
        if (null === $instance) {
39
            $instance = new static();
40
        }
41
42
        return $instance;
43
    }
44
45
    /**
46
     * Return primary key signature
47
     *
48
     * @return array
49
     */
50
    abstract public function getPrimaryKey();
51
52
    /**
53
     * Get item by primary key(s)
54
     *
55
     * @param  mixed $primary
56
     * @return mixed
57
     * @throws NotImplementedException
58
     */
59 1
    public function readOne($primary)
60
    {
61 1
        throw new NotImplementedException();
62
    }
63
64
    /**
65
     * Get collection of items
66
     *
67
     * @param  integer $offset
68
     * @param  integer $limit
69
     * @param  array $params
70
     * @param  null $total
71
     * @return mixed
72
     * @throws NotImplementedException
73
     */
74 1
    public function readSet($offset = 0, $limit = self::DEFAULT_LIMIT, $params = array(), &$total = null)
0 ignored issues
show
Unused Code introduced by
The parameter $params 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...
75
    {
76 1
        throw new NotImplementedException();
77
    }
78
79
    /**
80
     * Create new item
81
     *
82
     * @param  array $data
83
     * @return mixed
84
     * @throws NotImplementedException
85
     */
86 1
    public function createOne($data)
87
    {
88 1
        throw new NotImplementedException();
89
    }
90
91
    /**
92
     * Create items
93
     *
94
     * @param  array $data
95
     * @return mixed
96
     * @throws NotImplementedException
97
     */
98 1
    public function createSet($data)
99
    {
100 1
        throw new NotImplementedException();
101
    }
102
103
    /**
104
     * Update item
105
     *
106
     * @param  mixed $primary
107
     * @param  array $data
108
     * @return integer
109
     * @throws NotImplementedException
110
     */
111 1
    public function updateOne($primary, $data)
112
    {
113 1
        throw new NotImplementedException();
114
    }
115
116
    /**
117
     * Update items
118
     *
119
     * @param  array $data
120
     * @return integer
121
     * @throws NotImplementedException
122
     */
123 1
    public function updateSet($data)
124
    {
125 1
        throw new NotImplementedException();
126
    }
127
128
    /**
129
     * Delete item
130
     *
131
     * @param  mixed $primary
132
     * @return integer
133
     * @throws NotImplementedException
134
     */
135 1
    public function deleteOne($primary)
136
    {
137 1
        throw new NotImplementedException();
138
    }
139
140
    /**
141
     * Delete items
142
     *
143
     * @param  array $data
144
     * @return integer
145
     * @throws NotImplementedException
146
     */
147 1
    public function deleteSet($data)
148
    {
149 1
        throw new NotImplementedException();
150
    }
151
152
    /**
153
     * Get realized methods
154
     *
155
     * @return array
156
     */
157
    public function getMethods()
158
    {
159
        $reflection = new \ReflectionObject($this);
160
        $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
161
162
        $available = array();
163
        $allow = [
164
            'readOne',
165
            'readSet',
166
            'createOne',
167
            'createSet',
168
            'updateOne',
169
            'updateSet',
170
            'deleteOne',
171
            'deleteSet',
172
        ];
173
174
        foreach ($methods as $method) {
175
            $className = $method->getDeclaringClass()->getName();
176
            $methodName = $method->getName();
177
178
            if (__CLASS__ != $className && in_array($methodName, $allow)) {
179
                $available[] = $methodName;
180
            }
181
        }
182
183
        return $available;
184
    }
185
}
186