Completed
Push — master ( 2e0e8b...76a437 )
by Scott
08:04
created

Cart::updateItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Bedard\Shop\Api;
2
3
use Log;
4
use Exception;
5
use Bedard\Shop\Classes\ApiController;
6
use Bedard\Shop\Repositories\CartRepository;
7
8
class Cart extends ApiController
9
{
10
    /**
11
     * Add an inventory to the cart.
12
     *
13
     * @param CartRepository $repository
14
     */
15
    public function add(CartRepository $repository)
16
    {
17
        try {
18
            $inventoryId = input('inventoryId');
19
            $quantity = input('quantity');
20
21
            return $repository->addInventory($inventoryId, $quantity);
22
        } catch (Exception $e) {
23
            Log::error($e->getMessage());
24
25
            abort(500, $e->getMessage());
26
        }
27
    }
28
29
    /**
30
     * Determine if a cart exists or not.
31
     *
32
     * @param  CartRepository $repository
33
     * @return bool
34
     */
35 View Code Duplication
    public function exists(CartRepository $repository)
36
    {
37
        try {
38
            return $repository->exists() ? 'true' : 'false';
39
        } catch (Exception $e) {
40
            Log::error($e->getMessage());
41
42
            abort(500, $e->getMessage());
43
        }
44
    }
45
46
    /**
47
     * Show the current cart.
48
     *
49
     * @param  \Bedard\Shop\Repositories\CartRepository     $repository
50
     * @return \Bedard\Shop\Models\Cart
51
     */
52 View Code Duplication
    public function index(CartRepository $repository)
53
    {
54
        try {
55
            return $repository->loadCart();
56
        } catch (Exception $e) {
57
            Log::error($e->getMessage());
58
59
            abort(500, $e->getMessage());
60
        }
61
    }
62
63
    /**
64
     * Delete an item from the cart.
65
     *
66
     * @param  CartRepository $repository
67
     * @param  int            $inventoryId
68
     * @return \Bedard\Shop\Models\Cart
69
     */
70
    public function deleteItem(CartRepository $repository, $inventoryId)
71
    {
72
        try {
73
            $repository->deleteItem($inventoryId);
74
75
            return $repository->loadCart();
76
        } catch (Exception $e) {
77
            Log::error($e->getMessage());
78
79
            abort(500, $e->getMessage());
80
        }
81
    }
82
83
    /**
84
     * Create a new cart.
85
     *
86
     * @param  \Bedard\Shop\Repositories\CartRepository     $repository
87
     * @return \Bedard\Shop\Models\Cart
88
     */
89
    public function store(CartRepository $repository)
90
    {
91
        try {
0 ignored issues
show
Unused Code introduced by
This try statement is empty and can be removed.

This check looks for try blocks that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

If there is nothing in the try then the catch block can never be executed either. Thus, these try statements can be removed completely.

Loading history...
92
93
            // @todo
94
        } catch (Exception $e) {
0 ignored issues
show
Unused Code introduced by
catch (\Exception $e) { ...0, $e->getMessage()); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
95
            Log::error($e->getMessage());
96
97
            abort(500, $e->getMessage());
98
        }
99
    }
100
101
    public function updateItem(CartRepository $repository)
102
    {
103
        return 'hello';
104
    }
105
}
106