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