Completed
Push — master ( 0668ff...240876 )
by Alex
03:13
created

CalculatorApiController::getUserCalculs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Transformers\CalculatorTransformer;
6
use App\SimulatorHistory;
7
use App\User;
8
use Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController;
9
use DB;
10
use Illuminate\Http\Request;
11
use App\Http\Requests;
12
use Illuminate\Support\Facades\Auth;
13
use Illuminate\Support\Facades\Input;
14
15
/**
16
 * Class CalculatorApiController
17
 * @package App\Http\Controllers
18
 */
19
class CalculatorApiController extends ApiGuardController
20
{
21
22
    /**
23
     * @var CalculatorTransformer
24
     */
25
    protected $calcul_transformer;
26
27
    /**
28
     * @var SimulatorHistory
29
     */
30
    protected $calculator;
31
    /**
32
     * @var array
33
     */
34
    protected $apiMethods = [
35
        'store' =>[
36
            'keyAuthentication' => true
37
        ],
38
        'getUserCalculs' =>[
39
            'keyAuthentication' => true
40
        ]
41
    ];
42
43
    /**
44
     * CalculatorController constructor.
45
     * @param CalculatorTransformer $calcul_transformer
46
     * @param User $user
47
     * @param SimulatorHistory $calculator
48
     */
49
    public function __construct(CalculatorTransformer $calcul_transformer, User $user, SimulatorHistory $calculator)
50
    {
51
        parent::__construct();
52
53
54
        $this->calcul_transformer = $calcul_transformer;
55
        $this->user = $user;
56
        $this->calculator = $calculator;
57
    }
58
59
    /**
60
     *Store calculator data in DB
61
     * @param Request $request
62
     * @return mixed
63
     */
64
    public function store(Request $request)
65
    {
66
        $user = Auth::user();
67
68
        $calcul = array(
69
            'user_id' => $user->id,
70
            'name' => $request->input('name'),
71
            'quantity_to_buy' => $request->input('quantity_to_buy'),
72
            'quote_to_buy' => $request->input('quote_to_buy'),
73
            'price_to_buy' => $request->input('price_to_buy'),
74
            'quantity_to_sell' => $request->input('quantity_to_sell'),
75
            'quote_to_sell' => $request->input('quote_to_sell'),
76
            'tax_percent_to_discount' => $request->input('tax_percent_to_discount'),
77
            'price_to_sell' => $request->input('price_to_sell'),
78
            'gains_or_losses' => $request->input('gains_or_losses'),
79
        );
80
81
82
        $this->calculator->create($calcul);
83
84
       return $this->response->withItem($calcul, $this->calcul_transformer);
0 ignored issues
show
Documentation introduced by
$this->calcul_transformer is of type object<App\Http\Transfor...\CalculatorTransformer>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
    }
86
87 View Code Duplication
    public function getUserCalculs()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $user = Auth::user();
90
91
        $data = DB::table('simulator_history')->where('user_id','=',$user->id)->get();
92
93
        return $data;
94
    }
95
96
97
}
98