RequestsController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AraneaDev\Electrum\App\Api;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use AraneaDev\Electrum\Electrum;
7
use Illuminate\Http\Request;
8
9
/**
10
 * Class RequestsController.
11
 */
12
class RequestsController extends Controller
13
{
14
    /** @var Electrum */
15
    protected $electrum;
16
17
    /**
18
     * RequestsController constructor.
19
     *
20
     * @param  Electrum  $electrum
21
     */
22
    public function __construct(Electrum $electrum)
23
    {
24
        $this->middleware(config('electrum.web_interface.middleware', ['web', 'auth']));
25
        $this->electrum = $electrum;
26
    }
27
28
    /**
29
     * Show all payment requests.
30
     *
31
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32
     */
33
    public function index()
34
    {
35
        return response()->json($this->electrum->getRequests());
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...lectrum->getRequests()) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Contracts\Vie...ry|Illuminate\View\View.
Loading history...
36
    }
37
38
    /**
39
     * Show a payment request.
40
     *
41
     * @param $address
42
     * @return \Illuminate\Http\JsonResponse
43
     */
44
    public function show($address)
45
    {
46
        return response()->json($this->electrum->getRequest($address));
47
    }
48
49
    /**
50
     * Create a payment request.
51
     *
52
     * @param  Request  $request
53
     * @return \Illuminate\Http\JsonResponse
54
     */
55
    public function create(Request $request)
56
    {
57
        $request->validate([
58
            'amount' => 'required|numeric|min:0',
59
            'expires' => 'required|integer|min:0',
60
            'memo' => 'nullable',
61
        ]);
62
63
        return response()->json($this->electrum->createRequest(
64
            $request->get('amount'),
65
            $request->get('memo'),
66
            $request->get('expires')
67
        ));
68
    }
69
70
    /**
71
     * Remove a payment request.
72
     *
73
     * @param $address
74
     * @return \Illuminate\Http\JsonResponse
75
     */
76
    public function destroy($address)
77
    {
78
        return response()->json($this->electrum->clearRequest($address));
79
    }
80
81
    /**
82
     * Remove all payment requests.
83
     *
84
     * @return \Illuminate\Http\JsonResponse
85
     */
86
    public function clear()
87
    {
88
        return response()->json($this->electrum->clearRequests());
89
    }
90
}
91