Completed
Push — master ( 6ee175...4a5f9e )
by
unknown
01:25
created

VueOpdController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 123
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 3

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B index() 0 31 4
A create() 0 4 1
A store() 0 4 1
A show() 0 4 1
A edit() 0 4 1
A update() 0 4 1
A destroy() 0 12 2
1
<?php
2
3
namespace Bantenprov\VueOpd\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Bantenprov\BudgetAbsorption\Facades\VueOpdFacade;
9
10
/* Models */
11
use Bantenprov\VueOpd\Models\Bantenprov\VueOpd\VueOpd;
12
13
/* Etc */
14
use Validator;
15
16
/**
17
 * The VueOpdController class.
18
 *
19
 * @package Bantenprov\VueOpd
20
 * @author  bantenprov <[email protected]>
21
 */
22
class VueOpdController extends Controller
23
{
24
    /**
25
     * Create a new controller instance.
26
     *
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct(VueOpd $vue_opd)
30
    {
31
        $this->vue_opd = $vue_opd;
32
    }
33
34
    /**
35
     * Display a listing of the resource.
36
     *
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function index(Request $request)
40
    {
41
        if (request()->has('sort')) {
42
            list($sortCol, $sortDir) = explode('|', request()->sort);
43
44
            $query = $this->vue_opd->orderBy($sortCol, $sortDir);
45
        } else {
46
            $query = $this->vue_opd->orderBy('id', 'asc');
47
        }
48
49
        if ($request->exists('filter')) {
50
            $query->where(function($q) use($request) {
51
                $value = "%{$request->filter}%";
52
                $q->where('id', 'like', $value)
53
                    ->orWhere('kunker', 'like', $value)
54
                    ->orWhere('name', 'like', $value)
55
                    ->orWhere('kunker_sinjab', 'like', $value)
56
                    ->orWhere('kunker_simral', 'like', $value)
57
                    ->orWhere('levelunker', 'like', $value)
58
                    ->orWhere('njab', 'like', $value)
59
                    ->orWhere('npej', 'like', $value);
60
            });
61
        }
62
63
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
64
        $response = $query->paginate($perPage);
65
66
        return response()->json($response)
67
            ->header('Access-Control-Allow-Origin', '*')
68
            ->header('Access-Control-Allow-Methods', 'GET');
69
    }
70
71
    /**
72
     * Show the form for creating a new resource.
73
     *
74
     * @return \Illuminate\Http\Response
75
     */
76
    public function create()
77
    {
78
        //
79
    }
80
81
    /**
82
     * Display the specified resource.
83
     *
84
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
Bug introduced by
There is no parameter named $vue_opd. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function store(Request $request)
88
    {
89
        //
90
    }
91
92
    /**
93
     * Store a newly created resource in storage.
94
     *
95
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function show($id)
99
    {
100
        //
101
    }
102
103
    /**
104
     * Show the form for editing the specified resource.
105
     *
106
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
Bug introduced by
There is no parameter named $vue_opd. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
107
     * @return \Illuminate\Http\Response
108
     */
109
    public function edit($id)
110
    {
111
        //
112
    }
113
114
    /**
115
     * Update the specified resource in storage.
116
     *
117
     * @param  \Illuminate\Http\Request  $request
118
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
Bug introduced by
There is no parameter named $vue_opd. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
119
     * @return \Illuminate\Http\Response
120
     */
121
    public function update(Request $request, $id)
122
    {
123
        //
124
    }
125
126
    /**
127
     * Remove the specified resource from storage.
128
     *
129
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
Bug introduced by
There is no parameter named $vue_opd. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
130
     * @return \Illuminate\Http\Response
131
     */
132
    public function destroy($id)
133
    {
134
        $vue_opd = $this->vue_opd->findOrFail($id);
135
136
        if ($vue_opd->delete()) {
137
            $response['status'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
138
        } else {
139
            $response['status'] = false;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
140
        }
141
142
        return json_encode($response);
143
    }
144
}
145