Completed
Push — master ( f5e63f...0e343e )
by Alex
09:04
created

CompaniesTableFeeder::storeDataInDB()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\InteractionMethodsMOD\GetMethods;
6
use Carbon\Carbon;
7
use DB;
8
use GuzzleHttp\Client;
9
use Illuminate\Console\Command;
10
11
class CompaniesTableFeeder extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'companies_table:feed';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Feed the table companies from DB';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $this->getSymbolsFormArray();
45
    }
46
47
    public function getSymbolsFormArray()
48
    {
49
        DB::table('companies')->truncate();
50
51
        $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"]}';
52
53
        $symbols_nasdq = json_decode($symbols_nasdq);
54
55
        $symbols_nasdq = $symbols_nasdq->SymbolsNASDAQ;
56
57 View Code Duplication
        for($i=0; $i<count($symbols_nasdq); $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...
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
58
        {
59
            $symbol=$symbols_nasdq[$i];
60
            $gm = new GetMethods();
61
            $this->httpCall($gm,$symbol);
62
        }
63
    }
64
65
    public function httpCall(GetMethods $interaction_methods, $symbol)
66
    {
67
        $glz_cli=new Client();
68
69
        $data = $interaction_methods->companyLookup($glz_cli,$symbol);
70
71
        $this->discardRepeated($data,$symbol);
72
73
    }
74
75
    public function discardRepeated($data,$symbol)
76
    {
77
        for($i=0;$i<count($data);$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...
78
79
            $symbol_to_compare=(string) $data[$i]->Symbol;
80
81
            if($symbol_to_compare==$symbol){
82
83
                $node=$data[$i];
84
85
                $this->storeDataInDB($node);
86
            }
87
        }
88
    }
89
90
    public function storeDataInDB($data)
91
    {
92
        DB::table('companies')->insert([
93
            [
94
                'symbol' => $data->Symbol,
95
                'name' => $data->Name,
96
                'exchange' => $data->Exchange,
97
                'created_at' => Carbon::now()->toDateTimeString(),
98
                'updated_at' => Carbon::now()->toDateTimeString()
99
            ]
100
        ]);
101
    }
102
103
104
}