Completed
Push — master ( d1ecb8...6399e4 )
by Julien
03:46 queued 23s
created

MainController::done()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 21
loc 21
rs 9.3143
cc 1
eloc 11
nc 1
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\Redirect;
13
use Illuminate\Support\Facades\Validator;
14
use Netshell\Paypal\Facades\Paypal;
15
16
17
/**
18
 * Class MainController
19
 * V2 Fin de promotion
20
 * texte pour exemple
21
 * 2eme modif
22
 * @package App\Http\Controllers
23
 * Sufficé par le mot clef Controller
24
 * et doit hérité de la super classe Controller
25
 */
26
class MainController extends Controller{
27
28
29
    /**
30
     * Page Acceuil
31
     */
32
    public function index(){
33
34
        return view('Main/index');
35
    }
36
37
38
    public function ajaxmovies(Request $request){
39
40
        $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...
41
42
        $validator = Validator::make(
43
            $request->all(),  //request all : tous les elements de requetses
44
            [
45
            'title' => 'required|min:10',
46
            ],[
47
            'title.required' => "Votre titre est obligatoire",
48
            'title.min' => "Votre titre est trop court"
49
            ]);
50
51
        if ($validator->fails()) { // si mon validateur échoue
52
            return $validator->errors()->all();
53
        }else{
54
            Movies::create([
55
                'title' => $request->title,
56
                'description' => $request->description,
57
                'categories_id' => $request->categories_id
58
            ]);
59
60
            return $request->title;
61
        }
62
63
64
65
66
    }
67
68
69
70 View Code Duplication
    public function done(Request $request)
0 ignored issues
show
Duplication introduced by
This method 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...
71
    {
72
        $id = $request->get('paymentId');
73
        $token = $request->get('token');
0 ignored issues
show
Unused Code introduced by
$token 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...
74
        $payer_id = $request->get('PayerID');
75
76
        $payment = PayPal::getById($id, $this->_apiContext);
0 ignored issues
show
Bug introduced by
The property _apiContext does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
77
78
        $paymentExecution = PayPal::PaymentExecution();
79
80
        $paymentExecution->setPayerId($payer_id);
81
        $executePayment = $payment->execute($paymentExecution, $this->_apiContext);
82
83
        // Clear the shopping cart, write to database, send notifications, etc.
84
        $request->session()->pull('likes', []);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
86
87
        exit(dump($executePayment));
0 ignored issues
show
Coding Style Compatibility introduced by
The method done() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
88
        // Thank the user for the purchase
89
        return view('Main/index');
0 ignored issues
show
Unused Code introduced by
// Thank the user for th...urn view('Main/index'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
90
    }
91
92
    /**
93
     * Page Acceuil
94
     */
95
    public function dashboard(){
96
97
98
       // $redirectUrl = $response->links[1]->href;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
99
100
        $nbacteurs = Actors::count();
101
        $nbcommentaires = Comments::count();
102
        $nbmovies = Movies::count();
103
        $nbseances = Sessions::count();
104
105
        $actor = new Actors(); // Je récpere mon modèle
106
        $comment = new Comments(); // Je récpere mon modèle
107
        $movie = new Movies(); // Je récpere mon modèle
108
        $session = new Sessions(); // Je récpere mon modèle
109
        $user = new User(); // Je récpere mon modèle
110
111
        $avgacteurs = $actor->getAvgActors();
112
        $avgnotecommentaire = $comment->getAvgNote();
113
        $avgnotepresse = $movie->getAvgNotePresse();
114
        $avghour = $session->getAvgHourDate();
115
116
        $seances = $session->getNextSession();
117
        $users = $user->getLastUsers();
118
119
//        exit(dump($users));
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
120
121
        /*
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...
122
         $seances = Sessions::where("date_session",  ">", DB::raw("NOW()"))
123
        ->take(15)->get();
124
        */
125
126
        return view('Main/dashboard',[
127
            'avgnotecommentaire' => $avgnotecommentaire->avgnote,
128
            'avgnotepresse' => $avgnotepresse->avgpress,
129
            'avgacteurs' => $avgacteurs->age,
130
            'avghour' => $avghour->avghour,
131
            'nbacteurs' => $nbacteurs,
132
            'nbcommentaires' => $nbcommentaires,
133
            'nbmovies' => $nbmovies,
134
            'nbseances' => $nbseances,
135
            'seances' => $seances,
136
            'users' => $users,
137
        ]);
138
    }
139
140
141
}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160