CompaniesTableFeeder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 3
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 Cache;
9
use DB;
10
use Exception;
11
use Illuminate\Console\Command;
12
13
/**
14
 * Class CompaniesTableFeeder
15
 * @package App\Console\Commands
16
 */
17
class CompaniesTableFeeder extends Command
18
{
19
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 = 'companies_table:feed';
42
43
    /**
44
     * The console command description.
45
     *
46
     * @var string
47
     */
48
    protected $description = 'Feed the table companies 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
     * Execute the console command.
68
     *
69
     * @return mixed
70
     */
71
    public function handle()
72
    {
73
        $table='companies';
74
75
        DB::table($table)->truncate();
76
77
        $symbols_nasdq= '{"SymbolsNASDAQ":["AAL","AAPL","ADBE","ADI","ADP","ADSK","AKAM","ALXN","AMAT","AMGN","AMZN","ATVI","BBBY","BIDU","BIIB","BMRN","CA","CELG","CERN","CHKP","CHTR","CMCSA","COST","CSCO","CSX","CTRP","CTSH","CTXS","DISCA","DISCK","DISH","DLTR","EA","EBAY","ENDP","ESRX","EXPE","FAST","FB","FISV","FOX","FOXA","GILD","GOOG","HSIC","INCY","INTC","INTU","ILMN","ISRG","JD","KHC","LBTYA","LBTYK","LLTC","LMCA","LRCX","LVNTA","MAR","MAT","MDLZ","MNST","MSFT","MU","MXIM","MYL","NCLH","NFLX","NTAP","NVDA","NXPI","ORLY","PAYX","PCAR","PCLN","PYPL","QCOM","QVCA","REGN","ROST","SBAC","SBUX","SIRI","SNDK","SRCL","STX","SWKS","SYMC","TMUS","TSCO","TSLA","TRIP","TXN","ULTA","VIAB","VOD","VRSK","VRTX","WBA","WDC","WFM","XLNX","YHOO"]}';
78
79
        $symbols_nasdq = json_decode($symbols_nasdq);
80
81
        $symbols = $symbols_nasdq->SymbolsNASDAQ;
82
83
        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...
84
            try{
85
                $symbol=$symbols[$i];
86
                $data=$this->http_calls->getCompanies($symbol);
87
                $this->db_functions->storeCompanies($data);
88
                $this->progress_control->progressControl($i);
89
90
            }catch(Exception $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
91
92
            }
93
        }
94
        Cache::tags('companies')->flush();
95
        echo("100% Table companies fed\n");
96
    }
97
}