Inventories::validate()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 13
loc 13
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 9
nc 6
nop 0
1
<?php namespace Bedard\Shop\Controllers;
2
3
use Bedard\Shop\Classes\BackendController;
4
use Bedard\Shop\Models\Inventory;
5
use Exception;
6
use Response;
7
8
/**
9
 * Categories Back-end Controller.
10
 */
11
class Inventories extends BackendController
12
{
13
    /**
14
     * Create an inventory.
15
     *
16
     * @return Response
17
     */
18 View Code Duplication
    public function create()
19
    {
20
        try {
21
            // create our new inventory
22
            $data = input('inventory');
23
            unset($data['id']);
24
            $inventory = Inventory::create($data);
25
            $inventory->load('values');
26
27
            // return the new option
28
            return Response::make($inventory, 200);
29
        } catch (Exception $e) {
30
            // if anything went wrong, send back the error message
31
            return Response::make($e->getMessage(), 500);
32
        }
33
    }
34
35
    /**
36
     * Validate an inventory.
37
     *
38
     * @return Response
39
     */
40 View Code Duplication
    public function validate()
41
    {
42
        try {
43
            $data = input('inventory');
44
            $inventory = Inventory::findOrNew($data['id']);
45
            $inventory->fill($data);
46
            $inventory->validate();
47
48
            return Response::make($inventory, 200);
49
        } catch (Exception $e) {
50
            return Response::make($e->getMessage(), 500);
51
        }
52
    }
53
}
54