Completed
Push — master ( 5c637a...214bce )
by Julien
03:47
created

Twitter::handle()   C

Complexity

Conditions 12
Paths 96

Size

Total Lines 105
Code Lines 72

Duplication

Lines 75
Ratio 71.43 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 75
loc 105
rs 5.034
cc 12
eloc 72
nc 96
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Model\Stats;
6
use App\Model\Tweets;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\DB;
9
10
class Twitter extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'twitter:import';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Youtube import tweets on Mongo';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @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...
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
44
        $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany','format' => 'php']);
45
46 View Code Duplication
        if(!empty($infos)){
0 ignored issues
show
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...
47
            DB::connection('mongodb')->collection('stats')
48
                ->where(['origin' => 'Twitter', 'type' => 'infos'])->delete();
49
50
            $stat = new Stats();
51
            $stat->origin = "Twitter";
52
            $stat->type = "infos";
53
            $stat->data = $infos;
54
            $stat->save();
55
        }
56
57
58
        $tweets = \Thujohn\Twitter\Facades\Twitter::getDmsOut(['format' => 'php']);
59 View Code Duplication
        if(!empty($tweets)){
0 ignored issues
show
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...
60
61
            DB::connection('mongodb')->collection('tweets')
62
                ->where(['origin' => 'Twitter', 'type' => 'dmsout'])
63
                ->delete();
64
            foreach($tweets as $tweet){
65
                $vi = new Tweets();
66
                $vi->origin = "Twitter";
67
                $vi->type = "dmsout";
68
                $vi->data = $tweet;
69
                $vi->save();
70
            }
71
        }
72
73
        $tweets = \Thujohn\Twitter\Facades\Twitter::getFavorites(['format' => 'php']);
74 View Code Duplication
        if(!empty($tweets)){
0 ignored issues
show
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...
75
76
            DB::connection('mongodb')->collection('tweets')
77
                ->where(['origin' => 'Twitter', 'type' => 'favorites'])
78
                ->delete();
79
            foreach($tweets as $tweet){
80
                $vi = new Tweets();
81
                $vi->origin = "Twitter";
82
                $vi->type = "favorites";
83
                $vi->data = $tweet;
84
                $vi->save();
85
            }
86
        }
87
88
        $tweets = \Thujohn\Twitter\Facades\Twitter::getMentionsTimeline(
89
            [
90
                'count' => 15,
91
                'format' => 'php']);
92
93 View Code Duplication
        if(!empty($tweets)){
0 ignored issues
show
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...
94
95
            DB::connection('mongodb')->collection('tweets')
96
                ->where(['origin' => 'Twitter', 'type' => 'mentionstimeline'])
97
                ->delete();
98
            foreach($tweets as $tweet){
99
                $vi = new Tweets();
100
                $vi->origin = "Twitter";
101
                $vi->type = "mentionstimeline";
102
                $vi->data = $tweet;
103
                $vi->save();
104
            }
105
        }
106
107
        $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline(
108
            [
109
                'count' => 15,
110
                'format' => 'php']);
111
112 View Code Duplication
        if(!empty($tweets)){
0 ignored issues
show
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...
113
114
            DB::connection('mongodb')->collection('tweets')
115
                ->where(['origin' => 'Twitter', 'type' => 'hometimeline'])
116
                ->delete();
117
            foreach($tweets as $tweet){
118
                $vi = new Tweets();
119
                $vi->data = $tweet;
120
                $vi->origin = "Twitter";
121
                $vi->type = "hometimeline";
122
                $vi->save();
123
            }
124
        }
125
126
        $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline(
127
            [
128
                'screen_name' => 'allocine',
129
                'count' => 15,
130
                'format' => 'php']);
131
132 View Code Duplication
        if(!empty($tweets)){
0 ignored issues
show
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...
133
134
            DB::connection('mongodb')->collection('tweets')
135
                ->where(['origin' => 'Twitter', 'type' => 'usertimeline'])
136
                ->delete();
137
            foreach($tweets as $tweet){
138
                $vi = new Tweets();
139
                $vi->data = $tweet;
140
                $vi->origin = "Twitter";
141
                $vi->type = "usertimeline";
142
                $vi->save();
143
            }
144
        }
145
    }
146
}
147