Conditions | 3 |
Paths | 3 |
Total Lines | 33 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
15 | public function addAnnounce(Request $request){ |
||
16 | |||
17 | $file = null; |
||
|
|||
18 | |||
19 | |||
20 | // Build the input for our validation |
||
21 | $input = array('image' => Input::file('image')); |
||
22 | |||
23 | // Within the ruleset, make sure we let the validator know that this |
||
24 | // file should be an image |
||
25 | $rules = array( |
||
26 | 'image' => 'image' |
||
27 | ); |
||
28 | |||
29 | // Now pass the input and rules into the validator |
||
30 | $validator = Validator::make($input, $rules); |
||
31 | |||
32 | // Check to see if validation fails or passes |
||
33 | if ($validator->fails()) |
||
34 | { |
||
35 | return response()->json(['data' => 'Fichier invalid', 'state' => false]); |
||
36 | } else { |
||
37 | if ($request->hasFile('image')) { |
||
38 | $file = $request->file('image'); |
||
39 | $filename = $file->getClientOriginalName(); // Récupère le nom original du fichier |
||
40 | $destinationPath = public_path().'/uploads/ad'; // Indique où stocker le fichier |
||
41 | $file->move($destinationPath, $filename); // Déplace le fichier |
||
42 | return response()->json(['data' => asset($filename), 'state' => true]); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | |||
47 | } |
||
48 | |||
51 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.