CalcHistController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 10
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 8 1
A getSimulatorHistory() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use DB;
6
use Illuminate\Http\Request;
7
8
use App\Http\Requests;
9
use Illuminate\Support\Facades\Auth;
10
11
/**
12
 * Class CalcHistController
13
 * @package App\Http\Controllers
14
 */
15
class CalcHistController extends Controller
16
{
17
18
    /**
19
     * CalcHistController constructor.
20
     */
21
    public function __construct()
22
    {
23
        $this->middleware('auth');
24
    }
25
26
    /**
27
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
28
     */
29
    public function index()
30
    {
31
        $data_grid = $this->getSimulatorHistory();
32
33
        $columns="['id', 'name', 'quantity_to_buy', 'quote_to_buy', 'price_to_buy', 'quantity_to_sell', 'quote_to_sell', 'tax_percent_to_discount', 'price_to_sell', 'gains_or_losses']";
34
35
        return view('calculator_history', ['data_grid' => $data_grid, 'columns'=> $columns]);
36
    }
37
38
    /**
39
     * @return string
40
     */
41 View Code Duplication
    public function getSimulatorHistory()
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...
42
    {
43
        $user = Auth::user();
44
45
        $data = DB::table('simulator_history')->where('user_id','=',$user->id)->get();
46
47
        $data = json_encode($data);
48
49
        return $data;
50
    }
51
52
}
53