Passed
Push — dev5 ( 8481ee...a622eb )
by Ron
03:52 queued 01:34
created

CustomerFilesController::store()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
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