Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
RefreshTokenObserver | |
0.00% |
0 / 15 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
created | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
updated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCollection | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
findById | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
updateById | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace App\Observers; |
4 | |
5 | use App\Http\Models\Passport\RefreshToken; |
6 | use Illuminate\Support\Facades\DB; |
7 | |
8 | class RefreshTokenObserver |
9 | { |
10 | public function created(RefreshToken $refresh): void |
11 | { |
12 | $this->updateById($refresh->id); |
13 | } |
14 | |
15 | public function updated(RefreshToken $refresh): void |
16 | { |
17 | $this->updateById($refresh->id); |
18 | } |
19 | |
20 | private function getCollection() { |
21 | $mongodb = DB::connection('mongodb')->getDatabase(); |
22 | return $mongodb->selectCollection('oauth_refresh_tokens'); |
23 | } |
24 | |
25 | private function findById($id) { |
26 | $collection = $this->getCollection(); |
27 | |
28 | return $collection->findOne(['_id' => $id]); |
29 | } |
30 | |
31 | private function updateById($id) { |
32 | $collection = $this->getCollection(); |
33 | |
34 | $rawObject = $this->findById($id); |
35 | |
36 | if ((empty($rawObject) || empty($rawObject['id'])) && !empty($rawObject['_id'])) { |
37 | $collection->updateOne( |
38 | ['_id' => $id], |
39 | ['$set' => [ |
40 | 'id' => $id |
41 | ]] |
42 | ); |
43 | } |
44 | } |
45 | } |