ProxyController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 77
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 10 1
A index() 0 3 1
A store() 0 5 1
A show() 0 8 1
A __construct() 0 3 1
A update() 0 9 1
1
<?php
2
3
namespace Modules\Proxy\Http\Controllers;
4
5
use Foundation\Abstracts\Controller\Controller;
6
use Foundation\Responses\ApiResponse;
7
use Illuminate\Http\Request;
8
use Modules\Proxy\Contracts\ProxyServiceContract;
9
use Modules\Proxy\Transformers\ProxyTransformer;
10
11
class ProxyController extends Controller
12
{
13
    /**
14
     * @var ProxyServiceContract
15
     */
16
    protected $service;
17
18
    /**
19
     * ProxyController constructor.
20
     *
21
     * @param $service
22
     */
23
    public function __construct(ProxyServiceContract $service)
24
    {
25
        $this->service = $service;
26
    }
27
28
    /**
29
     * Display a listing of the resource.
30
     */
31
    public function index()
32
    {
33
        return ProxyTransformer::collection($this->service->getByUserId(get_authenticated_user_id()));
34
    }
35
36
    /**
37
     * Store a newly created Proxy in storage.
38
     */
39
    public function store(Request $request)
40
    {
41
        $proxy = $this->service->create($this->injectUserId($request));
42
43
        return ProxyTransformer::resource($proxy);
44
    }
45
46
    /**
47
     * Update a Proxy.
48
     *
49
     * @param Request $request
50
     */
51
    public function update(Request $request, $id)
52
    {
53
        $proxy = $this->service->find($id);
54
55
        $this->exists($proxy);
56
        $this->hasAccess($proxy);
57
        $proxy = $this->service->update($id, $request->toArray());
58
59
        return ProxyTransformer::resource($proxy);
60
    }
61
62
    /**
63
     * Show the specified resource.
64
     */
65
    public function show($id)
66
    {
67
        $proxy = $this->service->find($id);
68
69
        $this->exists($proxy);
70
        $this->hasAccess($proxy);
71
72
        return ProxyTransformer::resource($proxy);
73
    }
74
75
    /**
76
     * Remove the specified resource from storage.
77
     */
78
    public function destroy($id)
79
    {
80
        $proxy = $this->service->find($id);
81
82
        $this->exists($proxy);
83
        $this->hasAccess($proxy);
84
85
        $this->service->delete($proxy);
86
87
        return ApiResponse::deleted();
88
    }
89
}
90