Completed
Push — master ( 070a1e...ccce77 )
by Anton
12s
created

AbstractCrud::updateSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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