DataBaseFunctions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A truncateBDValuesAndGetNew() 0 8 1
A storeCompanyFollowTable() 0 15 1
A storeExchangeHistory() 0 17 1
A storeCompanies() 0 12 1
A getAllDataFromExchangeHistory() 0 6 1
1
<?php
2
3
namespace App\Console\AuxiliaryClasses;
4
5
use Carbon\Carbon;
6
use DB;
7
8
/**
9
 * Created by PhpStorm.
10
 * User: alumne
11
 * Date: 31/05/16
12
 * Time: 12:48
13
 */
14
class DataBaseFunctions
15
{
16
    /**
17
     * Delete Old data and get list of symbols
18
     *
19
     * @param $table_truncate
20
     * @return array|static[]
21
     */
22
    public function truncateBDValuesAndGetNew($table_truncate)
23
    {
24
        DB::table($table_truncate)->truncate();
25
26
        $symbols = DB::table('companies')->select('symbol')->get();
27
28
        return $symbols;
29
    }
30
31
    /**
32
     * Persist data to MYSQL
33
     *
34
     * @param $data
35
     * @param $table
36
     */
37
    public function storeCompanyFollowTable($data, $table)
38
    {
39
        DB::table($table)->insert([
40
            [
41
                'symbol' => $data->Symbol,
42
                'name' => $data->Name,
43
                'lastPrice' => $data->LastPrice,
44
                'change' => round($data->Change, 2),
45
                'volume' => $data->Volume,
46
                'open' => $data->Open,
47
                'created_at' => Carbon::now()->toDateTimeString(),
48
                'updated_at' => Carbon::now()->toDateTimeString()
49
            ]
50
        ]);
51
    }
52
53
    /**
54
     * Persist data to MYSQL
55
     *
56
     * @param $data
57
     * @param $table
58
     */
59
    public function storeExchangeHistory($data, $table)
60
    {
61
        DB::table($table)->insert([
62
            [
63
                'symbol' => $data->Elements[0]->Symbol,
64
                'positions' => json_encode($data->Positions),
65
                'dates' => json_encode($data->Dates),
66
                'values' => json_encode($data->Elements[0]->DataSeries->close->values),
67
                'max_date' =>  $data->Elements[0]->DataSeries->close->maxDate,
68
                'min_date' => $data->Elements[0]->DataSeries->close->minDate,
69
                'min_value' => $data->Elements[0]->DataSeries->close->min,
70
                'max_value' =>  $data->Elements[0]->DataSeries->close->max,
71
                'created_at' => Carbon::now()->toDateTimeString(),
72
                'updated_at' => Carbon::now()->toDateTimeString()
73
            ]
74
        ]);
75
    }
76
77
    /**
78
     * @param $data
79
     */
80
    public function storeCompanies($data)
81
    {
82
        DB::table('companies')->insert([
83
            [
84
                'symbol' => $data->Symbol,
85
                'name' => $data->Name,
86
                'exchange' => $data->Exchange,
87
                'created_at' => Carbon::now()->toDateTimeString(),
88
                'updated_at' => Carbon::now()->toDateTimeString()
89
            ]
90
        ]);
91
    }
92
93
    /**
94
     * @return array|static[]
95
     */
96
    public function getAllDataFromExchangeHistory()
97
    {
98
        $company_history = DB::table('exchange_history')->get();
99
100
        return $company_history;
101
    }
102
103
}