Completed
Push — master ( c06b9c...1f7b16 )
by Julien
13:04
created

MainController::ajaxmovies()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 29
rs 8.8571
cc 2
eloc 15
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
use App\Http\Models\Actors;
5
use App\Http\Models\Comments;
6
use App\Http\Models\Movies;
7
use App\Http\Models\Sessions;
8
use App\Http\Models\User;
9
use Carbon\Carbon;
10
use Illuminate\Http\Request;
11
use Illuminate\Support\Facades\DB;
12
use Illuminate\Support\Facades\Validator;
13
14
15
/**
16
 * Class MainController
17
 * @package App\Http\Controllers
18
 * Sufficé par le mot clef Controller
19
 * et doit hérité de la super classe Controller
20
 */
21
class MainController extends Controller{
22
23
    /**
24
     * Page Acceuil
25
     */
26
    public function index(){
27
28
        return view('Main/index');
29
    }
30
31
32
    public function ajaxmovies(Request $request){
33
34
        $title = $request->title;
1 ignored issue
show
Bug introduced by
The property title does not seem to exist in Illuminate\Http\Request.

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...
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
36
        $validator = Validator::make(
37
            $request->all(),  //request all : tous les elements de requetses
38
            [
39
            'title' => 'required|min:10',
40
            ],[
41
            'title.required' => "Votre titre est obligatoire",
42
            'title.min' => "Votre titre est trop court"
43
            ]);
44
45
        if ($validator->fails()) { // si mon validateur échoue
46
            return $validator->errors()->all();
47
        }else{
48
            Movies::create([
49
                'title' => $request->title,
50
                'description' => $request->description,
51
                'categories_id' => $request->categories_id
52
            ]);
53
54
            return $request->title;
55
        }
56
57
58
59
60
    }
61
62
63
    /**
64
     * Page Acceuil
65
     */
66
    public function dashboard(){
67
68
69
        $nbacteurs = Actors::count();
70
        $nbcommentaires = Comments::count();
71
        $nbmovies = Movies::count();
72
        $nbseances = Sessions::count();
73
74
        $actor = new Actors(); // Je récpere mon modèle
75
        $comment = new Comments(); // Je récpere mon modèle
76
        $movie = new Movies(); // Je récpere mon modèle
77
        $session = new Sessions(); // Je récpere mon modèle
78
        $user = new User(); // Je récpere mon modèle
79
80
        $avgacteurs = $actor->getAvgActors();
81
        $avgnotecommentaire = $comment->getAvgNote();
82
        $avgnotepresse = $movie->getAvgNotePresse();
83
        $avghour = $session->getAvgHourDate();
84
85
        $seances = $session->getNextSession();
86
        $users = $user->getLastUsers();
87
88
        //exit(dump($users));
0 ignored issues
show
Unused Code Comprehensibility introduced by
88% 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...
89
90
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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...
91
         $seances = Sessions::where("date_session",  ">", DB::raw("NOW()"))
92
        ->take(15)->get();
93
        */
94
95
        return view('Main/dashboard',[
96
            'avgnotecommentaire' => $avgnotecommentaire->avgnote,
97
            'avgnotepresse' => $avgnotepresse->avgpress,
98
            'avgacteurs' => $avgacteurs->age,
99
            'avghour' => $avghour->avghour,
100
            'nbacteurs' => $nbacteurs,
101
            'nbcommentaires' => $nbcommentaires,
102
            'nbmovies' => $nbmovies,
103
            'nbseances' => $nbseances,
104
            'seances' => $seances,
105
            'users' => $users,
106
        ]);
107
    }
108
109
}
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128