Completed
Push — master ( 6e8adf...c24137 )
by
unknown
27s
created

SiteController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\DataTables\SiteDataTable;
7
use App\Site;
8
9
class SiteController extends Controller
10
{
11
    /**
12
     * Create a new controller instance.
13
     */
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
    }
18
    
19
    /**
20
     * Display a listing of the resource.
21
     *
22
     * @param  SiteDataTable   $dataTable
23
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
24
     */
25
    public function index(SiteDataTable $dataTable)
26
    {
27
        return $dataTable->render('site.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $dataTable->render('site.index') also could return the type Illuminate\View\View|callable which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
28
    }
29
    
30
    /**
31
     * Show the form for creating a new resource.
32
     *
33
     * @return \Illuminate\Http\Response
34
     */
35
    public function create()
36
    {
37
        return view('site.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('site.create') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
38
    }
39
    
40
    /**
41
     * Store a newly created resource in storage.
42
     *
43
     * @param  \Illuminate\Http\Request  $request
44
     * @return \Illuminate\Http\RedirectResponse
45
     */
46 View Code Duplication
    public function store(Request $request)
47
    {
48
        $request->validate([
49
            'name' => 'required|min:2|max:190|name|unique:sites,name',
50
        ]);
51
        
52
        $site = Site::create([ 'name' => $request->name ]);
53
        
54
        return redirect()->route('site.show', $site->id)
0 ignored issues
show
Bug introduced by
$site->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        return redirect()->route('site.show', /** @scrutinizer ignore-type */ $site->id)
Loading history...
55
            ->with('success', 'Site created successfully');
56
    }
57
    
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param  int  $id
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function show($id)
65
    {
66
        $site = Site::findOrFail($id);
67
        $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15);
68
    
69
        if (\Request::ajax()) {
70
                    return response()->json(['site' => $site, 'locations' => $locations]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...ations' => $locations)) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
71
        } else {
72
                    return view('site.show', [ 'site' => $site, 'locations' => $locations ]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('site.show',...ations' => $locations)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
73
        }
74
    }
75
    
76
    /**
77
     * Show the form for editing the specified resource.
78
     *
79
     * @param  int  $id
80
     * @return \Illuminate\Http\Response
81
     */
82
    public function edit($id)
83
    {
84
        $site = Site::findOrFail($id);
85
        
86
        return view('site.edit', [ 'site' => $site ]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('site.edit', array('site' => $site)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
87
    }
88
    
89
    /**
90
     * Update the specified resource in storage.
91
     *
92
     * @param  \Illuminate\Http\Request  $request
93
     * @param  Site  $site
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96 View Code Duplication
    public function update(Request $request, Site $site)
97
    {
98
        $request->validate([
99
            'name' => 'required|min:2|max:190|name|unique:sites,name,'.$site->id,
100
        ]);
101
        
102
        $site->update([ 'name' => $request->name ]);
103
        
104
        return redirect()->route('site.show', $site->id)
0 ignored issues
show
Bug introduced by
$site->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
        return redirect()->route('site.show', /** @scrutinizer ignore-type */ $site->id)
Loading history...
105
            ->with('success', 'Site updated successfully');
106
    }
107
    
108
    /**
109
     * Remove the specified resource from storage.
110
     *
111
     * @param  int  $id
112
     * @return \Illuminate\Http\RedirectResponse
113
     */
114
    public function destroy($id)
115
    {
116
        Site::findOrFail($id)->delete();
117
        return redirect()->route('site.index')
118
            ->with('success', 'Site deleted successfully');
119
    }
120
}
121