Completed
Pull Request — master (#17)
by
unknown
08:29
created

ImageController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
ccs 0
cts 8
cp 0
cc 2
eloc 9
nc 2
nop 1
crap 6
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Intervention\Image\Facades\Image as Image;
7
8
class ImageController extends Controller
9
{
10
    /**
11
     * Create a new controller instance.
12
     *
13
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
    }
19
20
    /**
21
     * Show an image stored in private storage
22
     *
23
     * @param int $device_id
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function show($device_id)
27
    {
28
        $storagePath = storage_path('app/images/devices/');
29
        $imagePath = glob($storagePath . $device_id . "*" . ".jpg");
30
        
31
        if ($imagePath)
0 ignored issues
show
Bug Best Practice introduced by
The expression $imagePath of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            $image = Image::make($imagePath[0]);
33
        else
34
        {
35
            $imagePath = public_path() . '/img/video_not_found.jpg';
36
            $image = Image::make($imagePath);
37
        }
38
        
39
        return $image->response();
40
    }
41
    
42
    /**
43
     * Save an image's binary as a jpg to private storage
44
     *
45
     * @param int $device_id
46
     * @param string $binaryData
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function store($device_id, $binaryData)
50
    {
51
        $storagePath = storage_path('app/images/devices/') . $device_id . '.jpg';
52
        $image = Image::make($binaryData);
53
        $image->save($storagePath, 75);
54
    }
55
}
56