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 | { |
| 22 | $mongodb = DB::connection('mongodb')->getDatabase(); |
| 23 | |
| 24 | return $mongodb->selectCollection('oauth_refresh_tokens'); |
| 25 | } |
| 26 | |
| 27 | private function findById($id) |
| 28 | { |
| 29 | $collection = $this->getCollection(); |
| 30 | |
| 31 | return $collection->findOne(['_id' => $id]); |
| 32 | } |
| 33 | |
| 34 | private function updateById($id) |
| 35 | { |
| 36 | $collection = $this->getCollection(); |
| 37 | |
| 38 | $rawObject = $this->findById($id); |
| 39 | |
| 40 | if ((empty($rawObject) || empty($rawObject['id'])) && ! empty($rawObject['_id'])) { |
| 41 | $collection->updateOne( |
| 42 | ['_id' => $id], |
| 43 | ['$set' => [ |
| 44 | 'id' => $id, |
| 45 | ]] |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | } |