AutocompleteController::developer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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\Models\Developer;
11
use App\Models\Game;
12
use App\Models\User;
13
14
class AutocompleteController extends Controller
15
{
16
    /**
17
     * returns autocomplete values for games
18
     * @param $term
19
     * @return \Illuminate\Http\JsonResponse
20
     */
21
    public function search($term)
22
    {
23
        $result = [];
24
25
        $games = Game::search($term)->get();
26
27
        foreach ($games as $g) {
28
            $result[] = [
29
                'id'    => $g->id,
30
                'title' => $g->title,
31
                'value' => '<div class="searchresult">'.\View::make('_partials.inline_gamebox', ['game' => $g])->render().'</div>',
32
            ];
33
        }
34
35
        return \Response::json($result);
36
    }
37
38 View Code Duplication
    public function developer($term)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $result = [];
41
42
        $devs = Developer::where('name', 'like', '%'.$term.'%')->get();
43
44
        foreach ($devs as $dev) {
45
            $result[] = ['id' => $dev->id, 'value' => $dev->name];
46
        }
47
48
        return \Response::json($result);
49
    }
50
51
    public function game($term)
52
    {
53
        $result = [];
54
55
        $games = \DB::table('games')
56
            ->select([
57
                'id',
58
                'title',
59
                'subtitle',
60
            ])
61
            ->where('title', 'like', '%'.$term.'%')
62
            ->orWhere('subtitle', 'like', '%'.$term.'%')
63
            ->get();
64
65
        foreach ($games as $g) {
66
            if (is_null($g->subtitle) || $g->subtitle == '') {
67
                $result[] = ['id' => $g->id, 'value' => $g->title];
68
            } else {
69
                $result[] = ['id' => $g->id, 'value' => $g->title.' -=- '.$g->subtitle];
70
            }
71
        }
72
73
        return \Response::json($result);
74
    }
75
76
    public function faqcat($term)
77
    {
78
        $result = [];
79
80
        //$devs = Developer::whereName($term)->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
        $devs = \DB::table('faq')
82
            ->select(['id', 'cat'])
83
            ->where('faq.cat', 'like', '%'.$term.'%')
84
            ->groupBy('faq.cat')
85
            ->get();
86
87
        foreach ($devs as $dev) {
88
            $result[] = ['id' => $dev->id, 'value' => $dev->cat];
89
        }
90
91
        return \Response::json($result);
92
    }
93
94 View Code Duplication
    public function awardpage($term)
0 ignored issues
show
Unused Code introduced by
The parameter $term is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $result = [];
97
        $aw = \DB::table('award_pages')->get();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
98
99
        foreach ($aw as $item) {
100
            $result[] = [
101
                'id'    => $item->id,
102
                'value' => $item->title,
103
            ];
104
        }
105
106
        return \Response::json($result);
107
    }
108
109 View Code Duplication
    public function awardcat($term)
0 ignored issues
show
Unused Code introduced by
The parameter $term is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $result = [];
112
        $aw = \DB::table('award_cats')->get();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
113
114
        foreach ($aw as $item) {
115
            $result[] = [
116
                'id'    => $item->id,
117
                'value' => $item->title,
118
            ];
119
        }
120
121
        return \Response::json($result);
122
    }
123
124 View Code Duplication
    public function awardsubcat($term)
0 ignored issues
show
Unused Code introduced by
The parameter $term is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        $result = [];
127
        $aw = \DB::table('award_subcats')->get();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
128
129
        foreach ($aw as $item) {
130
            $result[] = [
131
                'id'    => $item->id,
132
                'value' => $item->title,
133
            ];
134
        }
135
136
        return \Response::json($result);
137
    }
138
139 View Code Duplication
    public function user($term)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $result = [];
142
        $users = User::where('name', 'like', '%'.$term.'%')->get();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
143
144
        foreach ($users as $user) {
145
            $result[] = [
146
                'id'    => $user->id,
147
                'value' => $user->name,
148
            ];
149
        }
150
151
        return \Response::json($result);
152
    }
153
}
154