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.

ScanController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllPointsPerUser() 0 5 1
B calcTotalPoints() 0 21 5
A showScan() 0 23 3
A checkCodeExists() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\DB;
7
8
class ScanController extends Controller
9
{
10
    /**
11
     * @param $param
12
     *
13
     * @return $this|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
14
     */
15
    public function showScan($param)
16
    {
17
        $rawQR = DB::select('SELECT * FROM game_codes WHERE  game_code = ?', [$param]);
18
        $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...
19
        $maxPoints = CodeCount::getTotalPoints();
20
21
        if (count($rawQR) > 0) {
22
            if (count($checkExists) < 1) {
23
                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...
24
                $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]);
25
                $checkExists = json_decode(json_encode($checkExists));
26
                $view = view('user.scan', ['checkExists' => $checkExists, 'maxPoints' => $maxPoints, 'first' => 1]);
27
            } else {
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])->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

30
                $view = view('user.scan', ['checkExists' => $checkExists, 'maxPoints' => $maxPoints])->withErrors(/** @scrutinizer ignore-type */ 'Der Code wurde bereits gezählt.');
Loading history...
31
            }
32
33
            $this->calcTotalPoints(Auth::user()->name_gen);
34
35
            return $view;
36
        } else {
37
            abort(404);
38
        }
39
    }
40
41
    /**
42
     * @param $code
43
     * @param $name_gen
44
     *
45
     * @return array
46
     */
47
    private function checkCodeExists($code, $name_gen)
48
    {
49
        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]);
50
    }
51
52
    /**
53
     * @param $name_gen
54
     */
55
    private function calcTotalPoints($name_gen)
56
    {
57
        $allPoints = $this->getAllPointsPerUser($name_gen);
58
59
        $totalPoints = 0;
60
        foreach ($allPoints as $point) {
61
            $totalPoints += $point['points'];
62
        }
63
64
        if ($totalPoints > 0) {
65
            DB::update('UPDATE users SET total_points = ? WHERE name_gen = ?;', [$totalPoints, $name_gen]);
66
        }
67
68
        if (count($allPoints) == 1) {
69
            DB::table('users')->where('id', Auth::User()->id)->limit(1)->update(['start' => Carbon::now()->toDateTimeString()]);
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Carbon was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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...
70
        }
71
72
        $codeCount = $this->getCodeCount();
0 ignored issues
show
Bug introduced by
The method getCodeCount() does not exist on App\Http\Controllers\ScanController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

72
        /** @scrutinizer ignore-call */ 
73
        $codeCount = $this->getCodeCount();
Loading history...
73
74
        if (count($allPoints) == $codeCount) {
75
            DB::table('users')->where('id', Auth::User()->id)->update(['end' => Carbon::now()->toDateTimeString()]);
76
        }
77
    }
78
79
    /**
80
     * @param $name_gen
81
     *
82
     * @return mixed
83
     */
84
    private function getAllPointsPerUser($name_gen)
85
    {
86
        $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]);
87
88
        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...
89
    }
90
}
91