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

ExchangeHistoryTableFeeder::httpCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
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 App\InteractionMethodsMOD\GetMethods;
9
use Carbon\Carbon;
10
use DB;
11
use GuzzleHttp\Client;
12
use Illuminate\Console\Command;
13
use Symfony\Component\Config\Definition\Exception\Exception;
14
15
/**
16
 * Class ExchangeHistoryTableFeeder
17
 * @package App\Console\Commands
18
 */
19 View Code Duplication
class ExchangeHistoryTableFeeder extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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 = 'history_table:feed';
42
43
    /**
44
     * The console command description.
45
     *
46
     * @var string
47
     */
48
    protected $description = 'Feed the table exchange_history 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
    /**
68
     * Execute the console command.
69
     *
70
     * @return mixed
71
     */
72
    public function handle()
73
    {
74
        $table='exchange_history';
75
76
        $symbols=$this->db_functions->truncateBDValuesAndGetNew($table);
77
78
        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...
79
            try{
80
81
                $symbol=$symbols[$i]->symbol;
82
                $data=$this->http_calls->getExchangeHistory($symbol);
83
                $this->db_functions->storeExchangeHistory($data,$table);
84
                $this->progress_control->progressControl($i);
85
86
            }catch(Exception $e){
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
87
88
            }
89
        }
90
        echo("100% Table exchange_history fed\n");
91
    }
92
}
93