Completed
Push — master ( f00659...1f4cdd )
by Julien
05:36
created

Actors::getAvgActors()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 5

Duplication

Lines 45
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 45
loc 45
rs 8.8571
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
8
9
/**
10
 * Classe qui va stocker mes requetes autoirs
11
 * de ma table movies
12
 * Hérite de ma super classe Model
13
 */
14 View Code Duplication
class Actors extends Model{
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...
15
16
    /**
17
     * Décrit le nom de la table
18
     * que classe fait référence
19
     */
20
    protected $table = 'actors';
21
22
23
24
    public function movies()
25
    {
26
        return $this->belongsToMany('\App\Http\Model\Movies');
27
    }
28
29
30
    /**
31
     * Retourne la moyenne d'age des acteurs
32
     * 1er mode de Laravel pour construire mes requetes
33
     * Cela me permet de conserver une syntaxe pure en Mysql
34
     */
35
    public function getAvgActors(){
36
37
        //1ere methode: Utilisation de MYSQL
38
        // marche mais n'est peu souple
39
         /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
          * $results = DB::select('
41
            SELECT ROUND(AVG(TIMESTAMPDIFF(YEAR,dob, NOW()))) as age
42
            FROM actors
43
        ');
44
         */
45
46
47
48
        // 2nd méthode: PHP & MYSQL
49
        // Query Builder: Le constructeur de Requête en Laravel
50
        // DB::table => correspond FROM actors en MYSQL
51
        // select() => corresponds a mon SELECT en MYSQL
52
        // DB::raw() => permet d'utiliser les fonctions MYSQL
53
        // comme ROUND() AVG() NOW()...
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
55
        // first() => corresponds LIMIT 1 en MYSQL
56
57
        // first() => l'equivalent de fetch()
58
        // get() => l'équivalent de fetchAll()
59
60
        // MAITRISE
61
62
          $results = DB::table('actors')
63
            ->select(DB::raw('ROUND(AVG(TIMESTAMPDIFF(YEAR,dob, NOW()))) as age'))
64
            ->first();
65
66
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
          $results = Actors::select(DB::raw('ROUND(AVG(TIMESTAMPDIFF(YEAR,dob, NOW()))) as age'))
68
            ->first();
69
        */
70
71
        //3eme methode: Eloquant ORM
72
        // Model Actors
73
        // <=> SELECT AVG(dob) FROM actors
74
        //$results = Actors::avg('dob');
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
76
        // je retourne le resultat de ma requete executé
77
        return $results;
78
79
    }
80
81
82
83
84
85
86
87
88
89
}
90
91
92
93