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.
Test Failed
Push — master ( a6bbd2...6f4a54 )
by Caspar
05:53
created

GenerateController::setCodeCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 1
eloc 2
c 2
b 2
f 0
nc 1
nop 1
dl 0
loc 5
rs 9.4285
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use DB;
6
use File;
7
use Illuminate\Http\Request;
8
use jeremykenedy\Uuid\Uuid;
9
use PDF;
10
use QrCode;
0 ignored issues
show
Bug introduced by
The type QrCode 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...
11
use App\Http\Controllers\CodeCount;
12
13
class GenerateController extends Controller
14
{
15
    /**
16
     * Defualt-View anzeigen.
17
     *
18
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
19
     */
20
    public function showGenerate()
21
    {
22
        return view('leader.generate');
23
    }
24
25
    /**
26
     * Code-Generierung initiieren.
27
     *
28
     * @param Request $request
29
     *
30
     * @throws \Exception
31
     *
32
     * @return \Illuminate\Http\RedirectResponse
33
     */
34
    public function index(Request $request)
35
    {
36
        $this->preCleanup();
37
38
        $countQR = CodeCount::setCodeCount($request['countQR']);
39
40
        for ($i = 0; $i < $countQR; ++$i) {
41
            $code = $this->generateCodes();
42
43
            $this->generateQR($code, $i);
44
        }
45
46
        if ($countQR > 0) {
47
            $this->generatePDF($countQR);
48
        }
49
50
        return back();
51
    }
52
53
    /**
54
     * Alte Daten löschen.
55
     */
56
    private function preCleanup()
57
    {
58
        DB::table('game_codes')->delete();
59
        DB::table('users_codes')->delete();
60
61
        DB::update('UPDATE users SET rank = NULL;');
62
        DB::update('UPDATE users SET total_points = NULL;');
63
        DB::table('game_admin')->delete();
64
65
        File::delete(File::glob(storage_path().'/pdf/codes/*.png'));
66
    }
67
68
    /**
69
     * UUIDs für die QR-Codes generieren.
70
     *
71
     * @throws \Exception
72
     *
73
     * @return mixed
74
     */
75
    private function generateCodes()
76
    {
77
        $code = uuid::generate(4);
78
79
        DB::table('game_codes')->insert(['game_code' => $code]);
80
81
        return $code;
82
    }
83
84
    /**
85
     * QR-Codes generieren.
86
     *
87
     * @param $code
88
     * @param $QRNumber
89
     */
90
    private function generateQR($code, $QRNumber)
91
    {
92
        QrCode::format('png')->size(200)->generate(url('/').'/user/qr/scan/'.$code, storage_path().'/pdf/codes/'.$QRNumber.'.png');
93
    }
94
95
    /**
96
     * PDF-File generieren.
97
     *
98
     * @param $fileCount
99
     */
100
    private function generatePDF($fileCount)
101
    {
102
        PDF::SetTitle(config('app.name'));
103
        PDF::SetFont('Arial', 'B', 18);
104
        PDF::SetMargins(10, 10, 10);
105
        PDF::SetCreator(config('app.name'));
106
        PDF::SetAuthor(config('app.name'));
107
108
        for ($i = 0; $i < $fileCount; $i++) {
109
            $j = $i;
110
            if ($fileCount - $i == 1) {
111
                PDF::AddPage();
112
                PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C');
113
                PDF::SetY(20);
114
                PDF::SetX(80);
115
                PDF::Image(storage_path().'/pdf/codes/'.$i.'.png');
116
                PDF::SetY(70);
117
                PDF::SetX(20);
118
                PDF::Image(storage_path().'/pdf/logo.png');
119
            } else {
120
                PDF::AddPage();
121
                PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C');
122
                PDF::SetY(20);
123
                PDF::SetX(80);
124
                PDF::Image(storage_path().'/pdf/codes/'.$i.'.png');
125
                PDF::SetY(70);
126
                PDF::SetX(20);
127
                PDF::Image(storage_path().'/pdf/logo.png');
128
129
                PDF::SetY(130);
130
                PDF::SetX(0);
131
                PDF::SetMargins(0, 10, 0);
132
                PDF::Cell(0, 0, '', 1, 1);
133
                PDF::SetY(150);
134
135
                PDF::Cell(0, 15, config('app.name').' - QR Nr. '.++$j, 0, 1, 'C');
136
                PDF::SetY(160);
137
                PDF::SetX(80);
138
                PDF::Image(storage_path().'/pdf/codes/'.++$i.'.png');
139
                PDF::SetY(210);
140
                PDF::SetX(20);
141
                PDF::Image(storage_path().'/pdf/logo.png');
142
            }
143
        }
144
145
        PDF::Output(storage_path().'/pdf/file/QR-Codes.pdf', 'F');
146
    }
147
}
148