Passed
Push — dev5 ( 03a57e...c2dc0b )
by Ron
09:22
created

CustomerFilesController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 43
ccs 14
cts 17
cp 0.8235
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 3 1
A destroy() 0 4 1
A update() 0 4 1
A __construct() 0 3 1
A show() 0 3 1
A store() 0 9 2
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use App\Http\Controllers\Controller;
6
7
use App\Domains\Customers\GetCustomerFiles;
8
use App\Domains\Customers\SetCustomerFiles;
9
use App\Domains\FileTypes\GetCustomerFileTypes;
10
11
use App\Http\Requests\CustomerFileNewRequest;
12
use App\Http\Requests\CustomerFileUpdateRequest;
13
14
class CustomerFilesController extends Controller
15
{
16 22
    public function __construct()
17
    {
18 22
        $this->middleware('auth');
19 22
    }
20
21
    //  Index funtion will return an array of file types that can be assigned to a file
22
    public function index()
23
    {
24
        return (new GetCustomerFileTypes)->execute(true);
25
    }
26
27
    //  Store a new customer file
28 4
    public function store(CustomerFileNewRequest $request)
29
    {
30
        //  Determine if a file is being uploaded still or not
31 4
        if((new SetCustomerFiles($request->cust_id))->createFile($request))
32
        {
33 4
            return response()->json(['success' => true]);
34
        }
35
36
        return response()->json(['success' =>false]);
37
    }
38
39
    //  Get the files for the customer
40 4
    public function show($id)
41
    {
42 4
        return (new GetCustomerFiles($id))->execute();
43
    }
44
45
    //  Update the information of the file, but not the file itself
46 4
    public function update(CustomerFileUpdateRequest $request, $id)
47
    {
48 4
        (new SetCustomerFiles($request->cust_id))->updateFile($request, $id);
49 4
        return response()->json(['success' => true]);
50
    }
51
52
    //  Remove a customer file
53 2
    public function destroy($id)
54
    {
55 2
        (new SetCustomerFiles($id))->deleteCustFile($id);
56 2
        return response()->json(['success' => true]);
57
    }
58
}
59