Completed
Pull Request — master (#831)
by
unknown
03:34
created

ResizeController::performResize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Xuandung38\LaravelFilemanager\Controllers;
4
5
use Intervention\Image\Facades\Image;
6
use Xuandung38\LaravelFilemanager\Events\ImageIsResizing;
7
use Xuandung38\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 Xuandung38\LaravelFilema...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()
56
    {
57
        $image_path = $this->lfm->setName(request('img'))->path('absolute');
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_path = $this->lfm->setName(/** @scrutinizer ignore-call */ request('img'))->path('absolute');
Loading history...
Bug Best Practice introduced by
The property lfm does not exist on Xuandung38\LaravelFilema...ollers\ResizeController. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
59
        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

59
        /** @scrutinizer ignore-call */ 
60
        event(new ImageIsResizing($image_path));
Loading history...
60
        Image::make($image_path)->resize(request('dataWidth'), request('dataHeight'))->save();
61
        event(new ImageWasResized($image_path));
62
63
        return parent::$success_response;
64
    }
65
}
66