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

Youtube   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 40 4
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Http\Models\Stats;
6
use App\Http\Models\Videos;
7
use Illuminate\Console\Command;
8
use Illuminate\Support\Facades\DB;
9
use Illuminate\Support\Facades\Log;
10
use Alaouy\Youtube\Facades\Youtube as Yt;
11
12
/**
13
 * Class Youtube
14
 * @package App\Console\Commands
15
 */
16
class Youtube extends Command
17
{
18
19
    /**
20
     * The name and signature of the console command.
21
     * @var string
22
     */
23
    protected $signature = 'youtube:import {keyword}';
24
25
    /**
26
     * The console command description.
27
     * @var string
28
     */
29
    protected $description = 'Youtube import videos on Mongo';
30
31
    /**
32
     * Create a new command instance.
33
     * @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...
34
     */
35
    public function __construct()
36
    {
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $keyword = $this->argument('keyword');
48
49
        $channel = Yt::getChannelByName('allocine');
50
51
        if(!empty($channel)) {
52
            DB::connection('mongodb')->collection('stats')
53
                ->where(['origin' => 'Youtube', 'type' => 'infos'])->delete();
54
55
            $stat = new Stats();
56
            $stat->origin = "Youtube";
0 ignored issues
show
Bug introduced by
The property origin does not seem to exist in App\Http\Models\Stats.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
57
            $stat->type = "infos";
0 ignored issues
show
Bug introduced by
The property type does not seem to exist in App\Http\Models\Stats.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
58
            $stat->data = $channel;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in App\Http\Models\Stats.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
59
            $stat->save();
0 ignored issues
show
Bug introduced by
The method save() does not seem to exist on object<App\Http\Models\Stats>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        }
61
62
        $params = array(
63
            'q'             => $keyword,
64
            'type'          => 'video',
65
            'part'          => 'id, snippet',
66
            'maxResults'    => 30
67
        );
68
69
        $videos = Yt::searchAdvanced($params, true)['results'];
70
71
        if(!empty($videos)){
72
73
            DB::connection('mongodb')->collection('videos')->delete();
74
            foreach($videos as $video){
75
                $vi = new Videos();
76
                $vi->data = $video;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist in App\Http\Models\Videos.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
77
                $vi->save();
0 ignored issues
show
Bug introduced by
The method save() does not seem to exist on object<App\Http\Models\Videos>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
            }
79
        }
80
81
        Log::info("Import de l'API Youtube video done! ");
82
83
84
    }
85
}
86