Completed
Push — master ( 9d175d...f5e63f )
by Alex
08:49
created

CompaniesTableFeeder::httpCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\InteractionMethodsMOD\GetMethods;
6
use Carbon\Carbon;
7
use DB;
8
use GuzzleHttp\Client;
9
use Illuminate\Http\Request;
10
11
use App\Http\Requests;
12
13
class CompaniesTableFeeder extends Controller
14
{
15
    
16
17
    public function getSymbolsFormArray()
18
    {
19
        $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"]}';
20
21
        $symbols_nasdq = json_decode($symbols_nasdq);
22
23
        $symbols_nasdq = $symbols_nasdq->SymbolsNASDAQ;
24
25 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...
26
        {
27
            $symbol=$symbols_nasdq[$i];
28
            $gm = new GetMethods();
29
            $this->httpCall($gm,$symbol);
30
31
        }
32
    }
33
34
    public function httpCall(GetMethods $interaction_methods, $symbol)
35
    {
36
        $glz_cli=new Client();
37
38
        $data = $interaction_methods->companyLookup($glz_cli,$symbol);
39
40
41
        $this->discardRepeated($data,$symbol);
42
43
    }
44
45
    public function discardRepeated($data,$symbol)
46
    {
47
        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...
48
49
            $symbol_to_compare=(string) $data[$i]->Symbol;
50
51
            if($symbol_to_compare==$symbol){
52
53
                $node=$data[$i];
54
55
                $this->storeDataInDB($node);
56
57
            }
58
59
        }
60
    }
61
62
    public function storeDataInDB($data)
63
    {
64
        DB::table('companies')->insert([
65
            [
66
                'symbol' => $data->Symbol,
67
                'name' => $data->Name,
68
                'exchange' => $data->Exchange,
69
                'created_at' => Carbon::now()->toDateTimeString(),
70
                'updated_at' => Carbon::now()->toDateTimeString()
71
            ]
72
        ]);
73
    }
74
}
75