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.

Media   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 26
dl 0
loc 117
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 4 1
A getCustomProperty() 0 3 1
A getDiskDriverName() 0 3 1
A img() 0 2 1
A toHtml() 0 3 1
A setCustomProperty() 0 9 1
A getFullUrl() 0 3 1
A toResponse() 0 19 2
1
<?php
2
3
namespace Raystech\StarterKit\Models;
4
5
use Illuminate\Contracts\Support\Htmlable;
6
use Illuminate\Contracts\Support\Responsable;
7
// use Raystech\MediaManager\Utils\File;
8
use Illuminate\Database\Eloquent\Model;
9
use Raystech\MediaManager\Models\Traits\CustomMediaProperties;
0 ignored issues
show
Bug introduced by
The type Raystech\MediaManager\Mo...s\CustomMediaProperties 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...
10
use Raystech\MediaManager\UrlGenerator\UrlGeneratorFactory;
0 ignored issues
show
Bug introduced by
The type Raystech\MediaManager\Ur...tor\UrlGeneratorFactory 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...
11
12
class Media extends Model implements Responsable, Htmlable
13
{
14
  use CustomMediaProperties;
15
16
  protected $casts = [
17
    'custom_properties' => 'array', // Will convarted to (Array)
18
	];
19
  public function toResponse($request)
20
  {
21
    $downloadHeaders = [
22
      'Cache-Control'       => 'must-revalidate, post-check=0, pre-check=0',
23
      'Content-Type'        => $this->mime_type,
0 ignored issues
show
Bug Best Practice introduced by
The property mime_type does not exist on Raystech\StarterKit\Models\Media. Did you maybe forget to declare it?
Loading history...
24
      'Content-Length'      => $this->size,
0 ignored issues
show
Bug Best Practice introduced by
The property size does not exist on Raystech\StarterKit\Models\Media. Did you maybe forget to declare it?
Loading history...
25
      'Content-Disposition' => 'attachment; filename="' . $this->file_name . '"',
0 ignored issues
show
Bug Best Practice introduced by
The property file_name does not exist on Raystech\StarterKit\Models\Media. Did you maybe forget to declare it?
Loading history...
26
      'Pragma'              => 'public',
27
    ];
28
29
    return response()->stream(function () {
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->strea... 200, $downloadHeaders) returns the type Symfony\Component\HttpFoundation\StreamedResponse which is incompatible with the return type mandated by Illuminate\Contracts\Sup...sponsable::toResponse() of Illuminate\Http\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
30
      $stream = $this->stream();
31
32
      fpassthru($stream);
33
34
      if (is_resource($stream)) {
35
        fclose($stream);
36
      }
37
    }, 200, $downloadHeaders);
38
  }
39
40
  public function toHtml()
41
  {
42
    return $this->img();
43
  }
44
  public function img($conversion = '', array $extraAttributes = []): string
45
  {
46
    // if (! (new Image())->canHandleMime($this->mime_type)) {
47
    //     return '';
48
    // }
49
50
    // if (is_array($conversion)) {
51
    //     $attributes = $conversion;
52
53
    //     $conversion = $attributes['conversion'] ?? '';
54
55
    //     unset($attributes['conversion']);
56
57
    //     $extraAttributes = array_merge($attributes, $extraAttributes);
58
    // }
59
60
    // $attributeString = collect($extraAttributes)
61
    //     ->map(function ($value, $name) {
62
    //         return $name.'="'.$value.'"';
63
    //     })->implode(' ');
64
65
    // if (strlen($attributeString)) {
66
    //     $attributeString = ' '.$attributeString;
67
    // }
68
69
    // $media = $this;
70
71
    // $viewName = 'image';
72
73
    // $width = '';
74
75
    // if ($this->hasResponsiveImages($conversion)) {
76
    //     $viewName = config('medialibrary.responsive_images.use_tiny_placeholders')
77
    //         ? 'responsiveImageWithPlaceholder'
78
    //         : 'responsiveImage';
79
80
    //     $width = $this->responsiveImages($conversion)->files->first()->width();
81
    // }
82
83
    // return view("medialibrary::{$viewName}", compact(
84
    //     'media',
85
    //     'conversion',
86
    //     'attributeString',
87
    //     'width'
88
    // ));
89
  }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
90
91
  public function getCustomProperty(string $propertyName, $default = null)
92
  {
93
    return array_get($this->custom_properties, $propertyName, $default);
94
  }
95
96
  /**
97
   * @param string $name
98
   * @param mixed $value
99
   *
100
   * @return $this
101
   */
102
  public function setCustomProperty(string $name, $value): self
103
  {
104
    $customProperties = $this->custom_properties;
105
106
    array_set($customProperties, $name, $value);
107
108
    $this->custom_properties = $customProperties;
0 ignored issues
show
Bug Best Practice introduced by
The property custom_properties does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
109
110
    return $this;
111
  }
112
  public function getDiskDriverName(): string
113
    {
114
        return strtolower(config("filesystems.disks.{$this->disk}.driver"));
0 ignored issues
show
Bug Best Practice introduced by
The property disk does not exist on Raystech\StarterKit\Models\Media. Did you maybe forget to declare it?
Loading history...
115
    }
116
117
    public function getFullUrl(string $conversionName = ''): string
118
    {
119
        return url($this->getUrl($conversionName));
120
    }
121
122
    /*
123
     * Get the url to a original media file.
124
     */
125
    public function getUrl(string $conversionName = ''): string
126
    {
127
        $urlGenerator = UrlGeneratorFactory::createForMedia($this, $conversionName);
128
        return $urlGenerator->getUrl();
129
    }
130
}
131