Passed
Push — master ( 9ce9b4...b185d8 )
by Stream
07:36 queued 03:17
created

ResizeController::performResizeNew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
use Intervention\Image\Facades\Image;
6
use UniSharp\LaravelFilemanager\Events\ImageIsResizing;
7
use UniSharp\LaravelFilemanager\Events\ImageWasResized;
8
9
class ResizeController extends LfmController
10
{
11
    /**
12
     * Dipsplay image for resizing.
13
     *
14
     * @return mixed
15
     */
16
    public function getResize()
17
    {
18
        $ratio = 1.0;
19
        $image = request('img');
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        $image = /** @scrutinizer ignore-call */ request('img');
Loading history...
20
21
        $original_image = Image::make($this->lfm->setName($image)->path('absolute'));
0 ignored issues
show
Bug introduced by
The method setName() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
        $original_image = Image::make($this->lfm->/** @scrutinizer ignore-call */ setName($image)->path('absolute'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...ollers\ResizeController. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
        $original_width = $original_image->width();
23
        $original_height = $original_image->height();
24
25
        $scaled = false;
26
27
        // FIXME size should be configurable
28
        if ($original_width > 600) {
29
            $ratio = 600 / $original_width;
30
            $width = $original_width * $ratio;
31
            $height = $original_height * $ratio;
32
            $scaled = true;
33
        } else {
34
            $width = $original_width;
35
            $height = $original_height;
36
        }
37
38
        if ($height > 400) {
39
            $ratio = 400 / $original_height;
40
            $width = $original_width * $ratio;
41
            $height = $original_height * $ratio;
42
            $scaled = true;
43
        }
44
45
        return view('laravel-filemanager::resize')
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::resize')
Loading history...
46
            ->with('img', $this->lfm->pretty($image))
47
            ->with('height', number_format($height, 0))
48
            ->with('width', $width)
49
            ->with('original_height', $original_height)
50
            ->with('original_width', $original_width)
51
            ->with('scaled', $scaled)
52
            ->with('ratio', $ratio);
53
    }
54
55
    public function performResize($overWrite = true)
56
    {
57
        $image_name = request('img');
0 ignored issues
show
Bug introduced by
The function request was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        $image_name = /** @scrutinizer ignore-call */ request('img');
Loading history...
58
        $image_path = $this->lfm->setName(request('img'))->path('absolute');
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...ollers\ResizeController. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
        $resize_path = $image_path;
60
61
        if (! $overWrite) {
62
            $fileParts = explode('.', $image_name);
63
            $fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_resized_' . time();
64
            $resize_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute');
65
        }
66
67
        event(new ImageIsResizing($image_path));
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        /** @scrutinizer ignore-call */ 
68
        event(new ImageIsResizing($image_path));
Loading history...
68
        Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save($resize_path);
69
        event(new ImageWasResized($image_path));
70
71
        return parent::$success_response;
72
    }
73
74
    public function performResizeNew()
75
    {
76
        $this->performResize(false);
77
    }
78
}
79