Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#228)
by Cristian
03:04 queued 01:38
created

RemoveBackpackuserModel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 10 1
A replaceModels() 0 25 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Support\Facades\DB;
5
use Illuminate\Support\Facades\Log;
6
7
class RemoveBackpackuserModel extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        // establish the table names
17
        $model_has_roles = config('permission.table_names.model_has_roles');
18
        $model_has_permissions = config('permission.table_names.model_has_permissions');
19
20
        // replace the BackpackUser model with User
21
        $this->replaceModels($model_has_roles);
22
        $this->replaceModels($model_has_permissions);
23
    }
24
25
    public function replaceModels($table_name)
26
    {
27
        Log::info('Replacing BackpackUser model in '.$table_name);
28
29
        // if you've ended up with duplicate entries (both for App\User and App\Models\BackpackUser)
30
        // we can just delete them
31
        $userEntries = DB::table($table_name)
32
            ->where('model_type', "App\User")
33
            ->get();
34
35
        foreach ($userEntries as $entry) {
36
            DB::table($table_name)
37
                ->where('role_id', $entry->role_id)
38
                ->where('model_type', 'App\Models\BackpackUser')
39
                ->where('model_id', $entry->model_id)
40
                ->delete();
41
        }
42
43
        // for the rest of them, we can just replace the BackpackUser model with User
44
        DB::table($table_name)
45
            ->where('model_type', "App\Models\BackpackUser")
46
            ->update([
47
                'model_type' => "App\User",
48
            ]);
49
    }
50
}
51