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 ( 466842...c61140 )
by Caspar
03:20
created

GenerateController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
dl 0
loc 133
rs 10
c 3
b 1
f 0
wmc 11

7 Methods

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