1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use App\Console\AuxiliaryClasses\DataBaseFunctions; |
6
|
|
|
use App\Console\AuxiliaryClasses\HttpCalls; |
7
|
|
|
use App\Console\AuxiliaryClasses\ProgressControl; |
8
|
|
|
use App\InteractionMethodsMOD\GetMethods; |
9
|
|
|
use Carbon\Carbon; |
10
|
|
|
use DB; |
11
|
|
|
use GuzzleHttp\Client; |
12
|
|
|
use Illuminate\Console\Command; |
13
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class ExchangeHistoryTableFeeder |
17
|
|
|
* @package App\Console\Commands |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
class ExchangeHistoryTableFeeder extends Command |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var DataBaseFunctions |
23
|
|
|
*/ |
24
|
|
|
protected $db_functions; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var HttpCalls |
28
|
|
|
*/ |
29
|
|
|
protected $http_calls; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ProgressControl |
33
|
|
|
*/ |
34
|
|
|
protected $progress_control; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The name and signature of the console command. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $signature = 'history_table:feed'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The console command description. |
45
|
|
|
* |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $description = 'Feed the table exchange_history from DB'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create a new command instance. |
52
|
|
|
* @param DataBaseFunctions $db_functions |
53
|
|
|
* @param HttpCalls $http_calls |
54
|
|
|
* @param ProgressControl $progress_control |
55
|
|
|
*/ |
56
|
|
|
public function __construct(DataBaseFunctions $db_functions,HttpCalls $http_calls,ProgressControl $progress_control) |
57
|
|
|
{ |
58
|
|
|
parent::__construct(); |
59
|
|
|
|
60
|
|
|
$this->db_functions=$db_functions; |
61
|
|
|
$this->http_calls=$http_calls; |
62
|
|
|
$this->progress_control=$progress_control; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Execute the console command. |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function handle() |
73
|
|
|
{ |
74
|
|
|
$table='exchange_history'; |
75
|
|
|
|
76
|
|
|
$symbols=$this->db_functions->truncateBDValuesAndGetNew($table); |
77
|
|
|
|
78
|
|
|
for($i=0; $i<count($symbols); $i++){ |
|
|
|
|
79
|
|
|
try{ |
80
|
|
|
|
81
|
|
|
$symbol=$symbols[$i]->symbol; |
82
|
|
|
$data=$this->http_calls->getExchangeHistory($symbol); |
83
|
|
|
$this->db_functions->storeExchangeHistory($data,$table); |
84
|
|
|
$this->progress_control->progressControl($i); |
85
|
|
|
|
86
|
|
|
}catch(Exception $e){ |
|
|
|
|
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
echo("100% Table exchange_history fed\n"); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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.