Completed
Push — master ( 648c39...33cf5d )
by Julien
14:10
created

AdController::addAnnounce()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
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 33
rs 8.8571
cc 3
eloc 15
nc 3
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
use Illuminate\Http\Request;
5
use Illuminate\Support\Facades\Input;
6
use Illuminate\Support\Facades\Validator;
7
8
9
/**
10
 * Class AdController.
11
 */
12
class AdController extends Controller
13
{
14
15
    public function addAnnounce(Request $request){
16
17
        $file = null;
0 ignored issues
show
Unused Code introduced by
$file 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...
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
49
50
}
51