Inventories   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 67.44 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 16 16 2
A validate() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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