Completed
Push — master ( 769dab...a13b06 )
by Scott
04:17
created

Inventories   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 17 4
1
<?php namespace Bedard\Shop\Controllers;
2
3
use Backend\Classes\Controller;
4
use Bedard\Shop\Models\Inventory;
5
use Exception;
6
use Response;
7
8
/**
9
 * Inventories Back-end Controller.
10
 */
11
class Inventories extends Controller
12
{
13
    /**
14
     * Validate an inventory.
15
     *
16
     * @return Response
17
     */
18
    public function validate()
19
    {
20
        $data = input('inventory');
21
        if (! $data || ! is_array($data)) {
22
            return Response::make('Error', 422);
23
        }
24
25
        try {
26
            $inventory = Inventory::firstOrNew(['id' => $data['id']]);
27
            $inventory->fill($data);
28
            $inventory->validate();
29
        } catch (Exception $e) {
30
            return Response::make($e->getMessage(), 400);
31
        }
32
33
        return Response::make($inventory, 200);
34
    }
35
}
36