LogoController::vote_add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 13
nc 2
nop 2
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use App\Events\Obyx;
11
use App\Models\Logo;
12
use App\Models\LogoVote;
13
use Illuminate\Http\Request;
14
15
class LogoController extends Controller
16
{
17
    public function vote_get()
18
    {
19
        $logos = [];
20
21
        if (\Auth::check()) {
22
            $logos = \DB::table('logos')
23
                ->leftJoin('logo_votes', 'logos.id', '=', 'logo_votes.logo_id')
24
                ->leftJoin('users', 'logos.user_id', '=', 'users.id')
25
                ->select(['logos.id', 'logos.filename', 'logos.title', 'users.name', 'logos.user_id'])
26
                ->whereNotExists(function ($query) {
27
                    $query->select(\DB::raw(1))
28
                        ->from('logo_votes')
29
                        ->whereRaw('logo_votes.logo_id = logos.id')
30
                        ->whereRaw('logo_votes.user_id = '.\Auth::id());
31
                })
32
                ->inRandomOrder()
33
                ->first();
34
35
        }
36
37
        return view('logo.index', ['logos' => $logos]);
38
    }
39
40
    public function vote_add($id, Request $request)
41
    {
42
        $lv = new LogoVote();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43
        $lv->logo_id = $id;
44
        $lv->user_id = \Auth::id();
45
        if ($request->get('value') == 0) {
46
            $lv->down = 1;
47
            $lv->up = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
48
        } else {
49
            $lv->down = 0;
50
            $lv->up = 1;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51
        }
52
53
        $lv->save();
54
55
        event(new Obyx('logo-vote', \Auth::id()));
56
57
        return \Redirect::back();
58
    }
59
}
60