Passed
Push — master ( 12bb50...fde0da )
by Aranea
36:18 queued 21:19
created

RequestsController::__construct()   A

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 Illuminate\Http\Request;
6
use AraneaDev\Electrum\Electrum;
7
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...
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\View\View|Ill...\Contracts\View\Factory.
Loading history...
Bug introduced by
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        return response()->/** @scrutinizer ignore-call */ json($this->electrum->getRequests());
Loading history...
36
    }
37
38
    /**
39
     * Show a payment request.
40
     *
41
     * @param $address
42
     *
43
     * @return \Illuminate\Http\JsonResponse
44
     */
45
    public function show($address)
46
    {
47
        return response()->json($this->electrum->getRequest($address));
48
    }
49
50
    /**
51
     * Create a payment request.
52
     *
53
     * @param Request $request
54
     *
55
     * @return \Illuminate\Http\JsonResponse
56
     */
57
    public function create(Request $request)
58
    {
59
        $request->validate([
60
            'amount'  => 'required|numeric|min:0',
61
            'expires' => 'required|integer|min:0',
62
            'memo'    => 'nullable',
63
        ]);
64
65
        return response()->json($this->electrum->createRequest(
66
            $request->get('amount'),
67
            $request->get('memo'),
68
            $request->get('expires')
69
        ));
70
    }
71
72
    /**
73
     * Remove a payment request.
74
     *
75
     * @param $address
76
     *
77
     * @return \Illuminate\Http\JsonResponse
78
     */
79
    public function destroy($address)
80
    {
81
        return response()->json($this->electrum->clearRequest($address));
82
    }
83
84
    /**
85
     * Remove all payment requests.
86
     *
87
     * @return \Illuminate\Http\JsonResponse
88
     */
89
    public function clear()
90
    {
91
        return response()->json($this->electrum->clearRequests());
92
    }
93
}
94