ExpenseCategoriesController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A archive() 0 5 1
A index() 0 7 1
A show() 0 5 1
A create() 0 3 1
A __construct() 0 3 1
A edit() 0 5 1
A store() 0 12 1
A update() 0 11 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Auth;
7
use App\ExpenseCategory;
8
use App\Http\Controllers\Controller;
9
use App\Http\Requests;
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 ExpenseCategoriesController extends Controller
13
{
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
    }
18
   
19
	/**
20
     * Display a listing of the resource.
21
     *
22
     * @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...
23
     */
24
    public function index()
25
    {
26
        $expenseCategories = ExpenseCategory::paginate(10);
27
    	$expenseCategoriesTotal = ExpenseCategory::all();
28
        $count = $expenseCategoriesTotal->count();
29
30
    	return view('expenseCategories.index', compact('expenseCategories','count'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('expenseCate...eCategories', 'count')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
31
    }
32
33
    /**
34
     * Display the specified resource.
35
     *
36
     * @param  int  $id
37
     * @return Response
38
     */
39
    public function show()
40
    {
41
    	$expenseCategory = ExpenseCategory::findOrFail($id);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
42
43
    	return view('expenseCategories.show', compact('expenseCategory'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('expenseCate...act('expenseCategory')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
44
    }
45
46
     /**
47
     * Show the form for creating a new resource.
48
     *
49
     * @return Response
50
     */
51
    public function create()
52
    {
53
    	return view('expenseCategories.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('expenseCategories.create') returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
54
    }
55
    
56
     /**
57
     * Store a newly created resource in storage.
58
     *
59
     * @return Response
60
     */
61
    public function store(Request $request)
62
    {
63
        $this->validate($request, ['name' => 'unique:mst_expenses_categories,name']);
64
65
        $expenseCategory = new ExpenseCategory($request->all());
66
67
        $expenseCategory->createdBy()->associate(Auth::user());
68
        $expenseCategory->updatedBy()->associate(Auth::user());
69
70
        $expenseCategory->save();
71
        flash()->success('Expense Category was successfully added');
72
    	return redirect('expenses/categories'); 
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('expenses/categories') returns the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
73
    }
74
75
    public function edit($id)
76
    {
77
        $expenseCategory=ExpenseCategory::findOrFail($id);
78
79
        return view('expenseCategories.edit', compact('expenseCategory'));
80
    }
81
82
    public function update($id, Request $request)
83
    {
84
        $expenseCategory=ExpenseCategory::findOrFail($id);
85
86
        $expenseCategory->update($request->all());
87
88
        $expenseCategory->updatedBy()->associate(Auth::user());
89
90
        $expenseCategory->save();
91
        flash()->success('Category was successfully updated');
92
        return redirect('expenses/categories');
93
    }    
94
    
95
    public function archive($id, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

95
    public function archive($id, /** @scrutinizer ignore-unused */ Request $request)

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

Loading history...
96
    {
97
        ExpenseCategory::destroy($id);
98
99
        return redirect('expenses/categories');
100
    }
101
}