Completed
Push — master ( 39c5ff...9d175d )
by Alex
07:50
created

ExchangeHistoryTableFeeder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSymbolsFormDB() 0 15 2
A httpCall() 0 8 1
A storeDataInDB() 0 17 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\InteractionMethodsMOD\GetMethods;
6
use Carbon\Carbon;
7
use DB;
8
use Illuminate\Http\Request;
9
10
use GuzzleHttp\Client;
11
12
use App\Http\Requests;
13
14
/**
15
 * Class ExchangeHistoryTableFeeder
16
 * @package App\Http\Controllers
17
 */
18
class ExchangeHistoryTableFeeder extends Controller
19
{
20
21
    /**
22
     *Elimina les dades antigues i n'insereix unes de noves
23
     */
24
    public function getSymbolsFormDB()
25
    {
26
        DB::table('exchange_history')->truncate();
27
28
        $symbols = DB::table('companies')->select('symbol')->get();
29
30
        for($i=0; $i<count($symbols); $i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
31
        {
32
            $symbol=$symbols[$i]->symbol;
33
            $gm = new GetMethods();
34
            $this->httpCall($gm,$symbol);
35
36
        }
37
38
    }
39
40
    /**
41
     * Aconegueix les dades de la api i fa la crida de la funció que les guardara a la BD
42
     *
43
     * @param GetMethods $interaction_methods
44
     * @param $symbol
45
     */
46
    public function httpCall(GetMethods $interaction_methods, $symbol)
47
    {
48
        $glz_cli=new Client();
49
50
        $data = $interaction_methods->interactiveChart($glz_cli,$symbol);
51
52
        $this->storeDataInDB($data);
53
    }
54
55
    /**
56
     *
57
     * Persisteix les dades al MYSQL
58
     *
59
     * @param $data
60
     */
61
    public function storeDataInDB($data)
62
    {
63
        DB::table('exchange_history')->insert([
64
            [
65
                'symbol' => $data->Elements[0]->Symbol,
66
                'positions' => json_encode($data->Positions),
67
                'dates' => json_encode($data->Dates),
68
                'values' => json_encode($data->Elements[0]->DataSeries->close->values),
69
                'max_date' =>  $data->Elements[0]->DataSeries->close->maxDate,
70
                'min_date' => $data->Elements[0]->DataSeries->close->minDate,
71
                'min_value' => $data->Elements[0]->DataSeries->close->min,
72
                'max_value' =>  $data->Elements[0]->DataSeries->close->max,
73
                'created_at' => Carbon::now()->toDateTimeString(),
74
                'updated_at' => Carbon::now()->toDateTimeString()
75
            ]
76
        ]);
77
    }
78
}
79