Twitter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
/**
8
 * Task to register all tweets
9
 * Class Twitter.
10
 */
11
class Twitter extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'twitter:import';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Twitter import tweets on Mongo';
26
27
    /**
28
     * Create a new command instance.
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $infos = \Thujohn\Twitter\Facades\Twitter::getUsersLookup(['screen_name' => 'Symfomany', 'format' => 'php']);
43
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
44
        $collection = new \MongoDB\Collection($manager, 'laravel.tweets');
0 ignored issues
show
Bug introduced by
The call to Collection::__construct() misses a required argument $collectionName.

This check looks for function calls that miss required arguments.

Loading history...
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'infos']);
48
49
            $stat = [
50
                'origin'  => 'Twitter',
51
                'type'    => 'infos',
52
                'data'    => $infos,
53
                'created' => new  \MongoDB\BSON\UTCDatetime(time()),
54
            ];
55
            $collection->insertOne($stat);
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'dmsout']);
61
62
            foreach ($tweets as $tweet) {
63
                $stat = [
64
                    'origin'  => 'Twitter',
65
                    'type'    => 'dmsout',
66
                    'data'    => $tweet,
67
                    'created' => new  \MongoDB\BSON\UTCDatetime(time()),
68
                ];
69
                $collection->insertOne($stat);
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'favorites']);
76
77
            foreach ($tweets as $tweet) {
78
                $stat = [
79
                    'origin'  => 'Twitter',
80
                    'type'    => 'favorites',
81
                    'data'    => $tweet,
82
                    'created' => new  \MongoDB\BSON\UTCDatetime(time()),
83
                ];
84
                $collection->insertOne($stat);
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'mentionstimeline']);
95
96
            foreach ($tweets as $tweet) {
97
                $stat = [
98
                    'origin'  => 'Twitter',
99
                    'type'    => 'mentionstimeline',
100
                    'data'    => $tweet,
101
                    'created' => new  \MongoDB\BSON\UTCDatetime(time()),
102
                ];
103
                $collection->insertOne($stat);
104
            }
105
        }
106
107
        $tweets = \Thujohn\Twitter\Facades\Twitter::getHomeTimeline([
108
                'count'  => 15,
109
                'format' => 'php',
110
            ]);
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'hometimeline']);
114
115
            foreach ($tweets as $tweet) {
116
                $stat = [
117
                    'origin'  => 'Twitter',
118
                    'type'    => 'hometimeline',
119
                    'data'    => $tweet,
120
                    'created' => new  \MongoDB\BSON\UTCDatetime(time()),
121
                ];
122
                $collection->insertOne($stat);
123
            }
124
        }
125
126
        $tweets = \Thujohn\Twitter\Facades\Twitter::getUserTimeline([
127
                'screen_name' => 'allocine',
128
                'count'       => 15,
129
                'format'      => 'php',
130
            ]);
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
            $collection->deleteMany(['origin' => 'Twitter', 'type' => 'usertimeline']);
134
135
            foreach ($tweets as $tweet) {
136
                $stat = [
137
                    'origin'  => 'Twitter',
138
                    'type'    => 'usertimeline',
139
                    'data'    => $tweet,
140
                    'created' => new  \MongoDB\BSON\UTCDatetime(time()),
141
                ];
142
                $collection->insertOne($stat);
143
            }
144
        }
145
    }
146
}
147