CropController::getCropImage()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 31
rs 9.6333
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
use Intervention\Image\Facades\Image as InterventionImageV2;
6
use Intervention\Image\Laravel\Facades\Image as InterventionImageV3;
0 ignored issues
show
Bug introduced by
The type Intervention\Image\Laravel\Facades\Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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

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

21
                'working_dir' => /** @scrutinizer ignore-call */ request('working_dir'),
Loading history...
22
                'img' => $this->lfm->pretty(request('img'))
0 ignored issues
show
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

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

31
        $image_name = /** @scrutinizer ignore-call */ request('img');
Loading history...
32
        $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...
33
        $crop_path = $image_path;
34
35
        if (! $overWrite) {
36
            $fileParts = explode('.', $image_name);
37
            $fileParts[count($fileParts) - 2] = $fileParts[count($fileParts) - 2] . '_cropped_' . time();
38
            $crop_path = $this->lfm->setName(implode('.', $fileParts))->path('absolute');
39
        }
40
41
        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

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