CompanyFollowTableFeeder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 4
dl 74
loc 74
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A handle() 20 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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