PlansController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 89
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 10 1
A create() 0 3 1
A edit() 0 5 1
A archive() 0 4 1
A index() 0 7 1
A store() 0 16 1
A show() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Auth;
7
use App\Plan;
8
use App\Http\Requests;
9
use App\Http\Controllers\Controller;
10
use Lubus\Constants\Status;
0 ignored issues
show
Bug introduced by
The type Lubus\Constants\Status 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 PlansController extends Controller
13
{
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
    }
18
	/**
19
     * Display a listing of the resource.
20
     *
21
     * @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...
22
     */
23
     public function index(Request $request)
24
    {
25
        $plans = Plan::excludeArchive()->search('"'.$request->input('search').'"')->paginate(10);
26
        $planTotal = Plan::excludeArchive()->search('"'.$request->input('search').'"')->get();
27
        $count = $planTotal->count();
28
        
29
    	return view('plans.index', compact('plans','count'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('plans.index...pact('plans', 'count')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
30
    }
31
32
     /**
33
     * Display the specified resource.
34
     *
35
     * @param  int  $id
36
     * @return Response
37
     */
38
    public function show()
39
    {
40
    	$plan = Plan::findOrFail($id);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
41
42
    	return view('plans.show', compact('plan'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('plans.show', compact('plan')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
43
    }
44
45
     /**
46
     * Show the form for creating a new resource.
47
     *
48
     * @return Response
49
     */
50
    public function create()
51
    {
52
    	return view('plans.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('plans.create') returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
53
    }
54
    
55
     /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @return Response
59
     */
60
    public function store(Request $request)
61
    {
62
        //Model Validation
63
        $this->validate($request, ['plan_code' => 'unique:mst_plans,plan_code',
64
                                   'plan_name' => 'unique:mst_plans,plan_name']);
65
66
        $plan = new Plan($request->all());
67
68
        $plan->createdBy()->associate(Auth::user());
69
        $plan->updatedBy()->associate(Auth::user());
70
71
        $plan->save();
72
73
        flash()->success('Plan was successfully created');
74
75
    	return redirect('plans'); 
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('plans') returns the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
76
    }
77
78
    public function edit($id)
79
    {
80
        $plan=Plan::findOrFail($id);
81
82
        return view('plans.edit', compact('plan'));
83
    }
84
85
    public function update($id, Request $request)
86
    {
87
88
        $plan=Plan::findOrFail($id);
89
90
        $plan->update($request->all());
91
        $plan->updatedBy()->associate(Auth::user());
92
        $plan->save();
93
        flash()->success('Plan details were successfully updated');
94
        return redirect('plans/all');
95
    }
96
97
    public function archive($id)
98
    {
99
        Plan::destroy($id);
100
        return redirect('plans/all');
101
    }
102
}
103