GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c31bff...117582 )
by Caspar
10:25
created

ScanController::checkCodeExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\User;
6
use Auth;
7
use Carbon\Carbon;
8
use DB;
9
10
class ScanController extends Controller
11
{
12
    /**
13
     * Grant scanned code or return issue.
14
     *
15
     * @param $param
16
     *
17
     * @return $this|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
18
     */
19
    public function showScan($param)
20
    {
21
        $rawQR = DB::select('SELECT * FROM game_codes WHERE  game_code = ?', [$param]);
22
        $checkExists = $this->checkCodeExists($param, Auth::user()->name_gen);
0 ignored issues
show
Bug introduced by
Accessing name_gen on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
23
        $maxPoints = CodeCount::getTotalPoints();
24
25
        if (count($rawQR) > 0) {
26
            if (count($checkExists) < 1) {
27
                DB::table('users_codes')->insert(['fk_users' => Auth::user()->id, 'fk_game_codes' => $rawQR[0]->id]);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
28
                $checkExists = DB::select('SELECT * FROM users RIGHT JOIN users_codes ON users.id = users_codes.fk_users RIGHT JOIN game_codes ON users_codes.fk_game_codes = game_codes.id WHERE name_gen = ? AND game_code = ?;', [Auth::user()->name_gen, $param]);
29
                $checkExists = json_decode(json_encode($checkExists));
30
                $view = view('user.scan', ['checkExists' => $checkExists, 'maxPoints' => $maxPoints, 'first' => 1]);
31
            } else {
32
                $checkExists = DB::select('SELECT * FROM users RIGHT JOIN users_codes ON users.id = users_codes.fk_users RIGHT JOIN game_codes ON users_codes.fk_game_codes = game_codes.id WHERE name_gen = ? AND game_code = ?;', [Auth::user()->name_gen, $param]);
33
                $checkExists = json_decode(json_encode($checkExists));
34
                $view = view('user.scan', ['checkExists' => $checkExists, 'maxPoints' => $maxPoints])->withErrors('Der Code wurde bereits gezählt.');
0 ignored issues
show
Bug introduced by
'Der Code wurde bereits gezählt.' of type string is incompatible with the type Illuminate\Contracts\Support\MessageProvider|array expected by parameter $provider of Illuminate\View\View::withErrors(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
                $view = view('user.scan', ['checkExists' => $checkExists, 'maxPoints' => $maxPoints])->withErrors(/** @scrutinizer ignore-type */ 'Der Code wurde bereits gezählt.');
Loading history...
35
            }
36
37
            $this->calcTotalPoints(Auth::user()->name_gen);
38
39
            return $view;
40
        } else {
41
            abort(404);
42
        }
43
    }
44
45
    /**
46
     * Check if scanned code is available in DB.
47
     *
48
     * @param $code
49
     * @param $name_gen
50
     *
51
     * @return mixed
52
     */
53
    private function checkCodeExists($code, $name_gen)
54
    {
55
        return DB::select('SELECT * FROM users RIGHT JOIN users_codes ON users.id = users_codes.fk_users RIGHT JOIN game_codes ON users_codes.fk_game_codes = game_codes.id WHERE name_gen = ? AND game_code = ?;', [$name_gen, $code]);
56
    }
57
58
    /**
59
     * Calculate total points of current user.
60
     *
61
     * @param $name_gen
62
     */
63
    private function calcTotalPoints($name_gen)
64
    {
65
        $allPoints = $this->getAllPointsPerUser($name_gen);
66
67
        $totalPoints = 0;
68
        foreach ($allPoints as $point) {
69
            $totalPoints += $point['points'];
70
        }
71
72
        if ($totalPoints > 0) {
73
            DB::update('UPDATE users SET total_points = ? WHERE name_gen = ?;', [$totalPoints, $name_gen]);
74
        }
75
76
        if (count($allPoints) == 1) {
77
            DB::table('users')->where('id', Auth::User()->id)->limit(1)->update(['start' => Carbon::now()->toDateTimeString()]);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
78
        }
79
80
        $codeCount = CodeCount::getCodeCount();
81
82
        if (count($allPoints) == $codeCount) {
83
            DB::table('users')->where('id', Auth::User()->id)->update(['end' => Carbon::now()->toDateTimeString()]);
84
        }
85
    }
86
87
    /**
88
     * Get all grantet points of current user.
89
     *
90
     * @param $name_gen
91
     *
92
     * @return mixed
93
     */
94
    private function getAllPointsPerUser($name_gen)
95
    {
96
        $pointsPerUser = DB::select('SELECT points,name_gen FROM users LEFT JOIN users_codes ON users.id = users_codes.fk_users LEFT JOIN game_codes ON users_codes.fk_game_codes = game_codes.id WHERE users.name_gen = ?;', [$name_gen]);
97
98
        return $pointsPerUserArray = json_decode(json_encode($pointsPerUser), true);
0 ignored issues
show
Unused Code introduced by
The assignment to $pointsPerUserArray is dead and can be removed.
Loading history...
99
    }
100
}
101