Completed
Push — master ( 04c9ff...5dea00 )
by Alex
03:36
created

CompaniesTableFeeder::getSymbolsFormArray()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 35
Code Lines 23

Duplication

Lines 22
Ratio 62.86 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 22
loc 35
rs 8.439
cc 6
eloc 23
nc 6
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A CompaniesTableFeeder::__construct() 0 9 1
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 DB;
9
use Exception;
10
use Illuminate\Console\Command;
11
12
/**
13
 * Class CompaniesTableFeeder
14
 * @package App\Console\Commands
15
 */
16
class CompaniesTableFeeder extends Command
17
{
18
19
20
    /**
21
     * @var DataBaseFunctions
22
     */
23
    protected $db_functions;
24
25
    /**
26
     * @var HttpCalls
27
     */
28
    protected $http_calls;
29
30
    /**
31
     * @var ProgressControl
32
     */
33
    protected $progress_control;
34
35
    /**
36
     * The name and signature of the console command.
37
     *
38
     * @var string
39
     */
40
    protected $signature = 'companies_table:feed';
41
42
    /**
43
     * The console command description.
44
     *
45
     * @var string
46
     */
47
    protected $description = 'Feed the table companies from DB';
48
49
    /**
50
     * Create a new command instance.
51
     * @param DataBaseFunctions $db_functions
52
     * @param HttpCalls $http_calls
53
     * @param ProgressControl $progress_control
54
     */
55
    public function __construct(DataBaseFunctions $db_functions,HttpCalls $http_calls,ProgressControl $progress_control)
56
    {
57
        parent::__construct();
58
59
        $this->db_functions=$db_functions;
60
        $this->http_calls=$http_calls;
61
        $this->progress_control=$progress_control;
62
63
    }
64
65
    /**
66
     * Execute the console command.
67
     *
68
     * @return mixed
69
     */
70
    public function handle()
71
    {
72
        $table='companies';
73
74
        DB::table($table)->truncate();
75
76
        $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","GOOGL","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"]}';
77
78
        $symbols_nasdq = json_decode($symbols_nasdq);
79
80
        $symbols = $symbols_nasdq->SymbolsNASDAQ;
81
82
        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...
83
            try{
84
                $symbol=$symbols[$i];
85
                $data=$this->http_calls->getCompanies($symbol);
86
                $this->db_functions->storeCompanies($data);
87
                $this->progress_control->progressControl($i);
88
89
            }catch(Exception $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
90
91
            }
92
        }
93
        echo("100% Table companies fed\n");
94
    }
95
}