Passed
Push — master ( 3fc28d...5a5320 )
by Stream
04:22
created

CropController::getNewCropImage()   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\ImageIsCropping;
7
use UniSharp\LaravelFilemanager\Events\ImageWasCropped;
8
9
class CropController extends LfmController
10
{
11
    /**
12
     * Show crop page.
13
     *
14
     * @return mixed
15
     */
16
    public function getCrop()
17
    {
18
        return view('laravel-filemanager::crop')
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

18
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::crop')
Loading history...
19
            ->with([
20
                'working_dir' => request('working_dir'),
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

20
                'working_dir' => /** @scrutinizer ignore-call */ request('working_dir'),
Loading history...
21
                'img' => $this->lfm->pretty(request('img'))
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...trollers\CropController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method pretty() 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
                'img' => $this->lfm->/** @scrutinizer ignore-call */ pretty(request('img'))

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...
22
            ]);
23
    }
24
25
    /**
26
     * Crop the image (called via ajax).
27
     */
28
    public function getCropImage($overWrite = true)
29
    {
30
        $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

30
        $image_name = /** @scrutinizer ignore-call */ request('img');
Loading history...
31
        $image_path = $this->lfm->setName($image_name)->path('absolute');
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...trollers\CropController. Since you implemented __get, consider adding a @property annotation.
Loading history...
32
        $crop_path = $image_path;
33
34
        if (! $overWrite) {
35
            $fileParts = explode('.', $image_name);
36
            $fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
37
            $crop_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute');
38
        }
39
40
        event(new ImageIsCropping($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

40
        /** @scrutinizer ignore-call */ 
41
        event(new ImageIsCropping($image_path));
Loading history...
41
42
        $crop_info = request()->only('dataWidth', 'dataHeight', 'dataX', 'dataY');
43
44
        // crop image
45
        Image::make($image_path)
46
            ->crop(...array_values($crop_info))
47
            ->save($crop_path);
48
49
        // make new thumbnail
50
        $this->lfm->generateThumbnail($image_name);
51
52
        event(new ImageWasCropped($image_path));
53
    }
54
55
    public function getNewCropImage()
56
    {
57
        $this->getCropimage(false);
58
    }
59
}
60