GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ImageTrait   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 50
dl 0
loc 95
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B imageResize() 0 81 11
1
<?php
2
3
namespace Raystech\StarterKit\Traits;
4
use Image;
5
6
trait ImageTrait
7
{
8
9
  /*
10
   |------------------------------------------------------------
11
   | @param  mixed  $image
12
   | @param  int    $width
13
   | @param  int    $height
14
   | @param  string $mode ['constrain', 'expand']
15
   | @param  int    $quality [0-100]
16
   |
17
   | @return \Intervention\Image\Image
0 ignored issues
show
Bug introduced by
The type Intervention\Image\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...
18
   |------------------------------------------------------------
19
   */
20
  private function imageResize($image, $width, $height = null, $mode = 'expand', $quality = 85) {
21
    if($height == null && $mode == 'expand') {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $height of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
22
      $height = $width;
23
    }
24
25
    $img    = Image::make($image->getRealPath());
26
    // $img = $image;
27
28
    $margin = 0;
29
30
    $img_width  = $img->width();
31
    $img_height = $img->height();
32
33
    /*
34
    *  canvas
35
    */
36
    $dimension  = $width;
37
    $desire_width = $width;
38
    $desire_height = $height;
39
40
    $vertical   = ($img_width < $img_height);
41
    $horizontal = ($img_width > $img_height);
42
    $square     = ($img_width = $img_height);
0 ignored issues
show
Unused Code introduced by
The assignment to $img_width is dead and can be removed.
Loading history...
43
44
    if($mode == 'expand') {
45
      if ($vertical) {
46
        $top = $bottom = $margin;
47
        $newHeight = ($dimension) - ($bottom + $top);
48
        $img->resize(null, $newHeight, function ($constraint) {
49
          $constraint->aspectRatio();
50
        });
51
52
      } else if ($horizontal) {
53
        $right = $left = $margin;
54
        $newWidth = ($dimension) - ($right + $left);
55
        $img->resize($newWidth, null, function ($constraint) {
56
          $constraint->aspectRatio();
57
        });
58
59
      } else if ($square) {
60
        $right = $left = $margin;
61
        $newWidth = ($dimension) - ($left + $right);
62
        $img->resize($newWidth, null, function ($constraint) {
63
          $constraint->aspectRatio();
64
        });
65
66
      }
67
68
      $img->resizeCanvas($dimension, $dimension, 'center', false, '#ffffff');
69
      $img->encode('jpg', $quality);
70
71
    } else if($mode == 'constrain') {
72
      if ($vertical) {
73
        $top = $bottom = $margin;
74
        $newHeight = ($desire_height) - ($bottom + $top);
75
        $img->resize(null, $newHeight, function ($constraint) {
76
          $constraint->aspectRatio();
77
        });
78
79
      } else if ($horizontal) {
80
        $right = $left = $margin;
81
        $newWidth = ($desire_width) - ($right + $left);
82
        $img->resize($newWidth, null, function ($constraint) {
83
          $constraint->aspectRatio();
84
        });
85
86
      } else if ($square) {
87
        $right = $left = $margin;
88
        $newWidth = ($desire_width) - ($left + $right);
89
        $img->resize($newWidth, null, function ($constraint) {
90
          $constraint->aspectRatio();
91
        });
92
93
      }
94
95
      $img->resizeCanvas($desire_width, $desire_height, 'center', false, '#ffffff');
96
      $img->encode('jpg', $quality);
97
    }
98
99
100
    return $img;
101
    // $img->save(public_path("storage/{$token}/{$origFilename}"));
102
  }
103
}