|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repositories; |
|
4
|
|
|
|
|
5
|
|
|
use App\Contracts\DBRepositoryInterface; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Support\Facades\DB; |
|
7
|
|
|
use Illuminate\Database\Query\Builder; |
|
8
|
|
|
use Illuminate\Pagination\LengthAwarePaginator; |
|
9
|
|
|
use Illuminate\Support\Collection; |
|
10
|
|
|
|
|
11
|
|
|
class DBRepository implements DBRepositoryInterface |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Fetch all \Illuminate\Support\Facades\DB records. |
|
16
|
|
|
* |
|
17
|
|
|
* @return \Illuminate\Support\Collection |
|
18
|
|
|
*/ |
|
19
|
|
|
public function getAll(string $table): Collection |
|
20
|
|
|
{ |
|
21
|
|
|
return DB::table($table)->get(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Fetch \Illuminate\Support\Facades\DB record by ID. |
|
26
|
|
|
* |
|
27
|
|
|
* @param int $id |
|
28
|
|
|
* @return mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getById(int $id, string $table): mixed |
|
31
|
|
|
{ |
|
32
|
|
|
return DB::table($table)->where('id', $id)->first(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Delete \Illuminate\Support\Facades\DB record by ID. |
|
37
|
|
|
* |
|
38
|
|
|
* @param int $id |
|
39
|
|
|
* @return int |
|
40
|
|
|
*/ |
|
41
|
|
|
public function delete(int $id, string $table): int |
|
42
|
|
|
{ |
|
43
|
|
|
return DB::table($table)->delete($id); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create \Illuminate\Support\Facades\DB record. |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $arrayDetails |
|
50
|
|
|
* @param string $table |
|
51
|
|
|
* @return int |
|
52
|
|
|
*/ |
|
53
|
|
|
public function create(array $arrayDetails, string $table): int |
|
54
|
|
|
{ |
|
55
|
|
|
return DB::table($table)->insertGetId($arrayDetails); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Update \Illuminate\Support\Facades\DB record. |
|
60
|
|
|
* |
|
61
|
|
|
* @param int $id |
|
62
|
|
|
* @param array $arrayDetails |
|
63
|
|
|
* @return int |
|
64
|
|
|
*/ |
|
65
|
|
|
public function update(int $id, array $arrayDetails, string $table): int |
|
66
|
|
|
{ |
|
67
|
|
|
return DB::table($table)->where('id', $id)->update($arrayDetails); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Update Multiple \Illuminate\Support\Facades\DB record. |
|
72
|
|
|
* |
|
73
|
|
|
* @param array $matchDetails |
|
74
|
|
|
* @param array $arrayDetails |
|
75
|
|
|
* @return int |
|
76
|
|
|
*/ |
|
77
|
|
|
public function updateWhereIn(array $matchDetails, array $arrayDetails, string $table): int |
|
78
|
|
|
{ |
|
79
|
|
|
return DB::table($table)->whereIn('id', $matchDetails)->update($arrayDetails); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Update \Illuminate\Support\Facades\DB record. |
|
84
|
|
|
* |
|
85
|
|
|
* @param int $pageSize |
|
86
|
|
|
* @return \Illuminate\Pagination\LengthAwarePaginator |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getPaginated(int $pageSize, string $table): LengthAwarePaginator |
|
89
|
|
|
{ |
|
90
|
|
|
return DB::table($table)->paginate($pageSize); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Query builder for validation |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $table |
|
97
|
|
|
* @return Builder |
|
98
|
|
|
*/ |
|
99
|
|
|
public function queryBuilder(string $table): Builder |
|
100
|
|
|
{ |
|
101
|
|
|
return DB::table($table); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Update or create \Illuminate\Support\Facades\DB record. |
|
106
|
|
|
* |
|
107
|
|
|
* @param array $matchDetails |
|
108
|
|
|
* @param array $arrayDetails |
|
109
|
|
|
* @param string $table |
|
110
|
|
|
* @return bool |
|
111
|
|
|
*/ |
|
112
|
|
|
public function updateOrCreate(array $matchDetails, array $arrayDetails, string $table): bool |
|
113
|
|
|
{ |
|
114
|
|
|
return DB::table($table)->updateOrInsert($matchDetails, $arrayDetails); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Create \Illuminate\Support\Facades\DB record. |
|
119
|
|
|
* |
|
120
|
|
|
* @param array $arrayDetails |
|
121
|
|
|
* @param string $table |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
|
|
public function insert(array $arrayDetails, string $table): bool |
|
125
|
|
|
{ |
|
126
|
|
|
return DB::table($table)->insert($arrayDetails); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths