Completed
Push — master ( df809c...204795 )
by Scott
04:21
created

Options::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.2
cc 4
eloc 10
nc 4
nop 0
1
<?php namespace Bedard\Shop\Controllers;
2
3
use BackendMenu;
4
use Backend\Classes\Controller;
5
use Bedard\Shop\Models\Option;
6
use Exception;
7
use Response;
8
9
/**
10
 * Options Back-end Controller
11
 */
12
class Options extends Controller
13
{
14
    /**
15
     * Validate an option
16
     *
17
     * @return Response
18
     */
19
    public function validate()
20
    {
21
        $data = input('option');
22
        if (!$data || !is_array($data)) {
23
            return Response::make('Error', 422);
24
        }
25
26
        try {
27
            $option = new Option($data);
28
            $option->validate();
29
        } catch (Exception $e) {
30
            return Response::make($e->getMessage(), 400);
31
        }
32
33
        return Response::make($option, 200);
34
    }
35
}
36