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.

SaveFileWhenAddingAttachment   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A creating() 0 22 3
1
<?php namespace Afrittella\BackProject\Models\Observers;
2
3
use Illuminate\Http\Request;
4
use Afrittella\BackProject\Models\Attachment;
5
use Illuminate\Support\Facades\Storage;
6
use Afrittella\BackProject\Facades\MediaManager;
7
8
class SaveFileWhenAddingAttachment
9
{
10
    protected $request;
11
12
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
13
    {
14
        $this->request = $request;
15
        //$this->media_path = Storage::disk()->getDriver()->getAdapter()->getPathPrefix();
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
16
    }
17
18
    public function creating(Attachment $attachment)
19
    {
20
        $file = $this->request->file('attachment');
21
22
        if (!empty($file)) {
23
            $img_name = MediaManager::hashName($file->getClientOriginalExtension());
24
            if (Storage::put($img_name, file_get_contents($file->getRealPath()), ['visibility' => 'public'])) {
25
                $attachment->name = $img_name;
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Afrittella\BackProject\Models\Attachment>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
26
                $attachment->original_name = $file->getClientOriginalName();
0 ignored issues
show
Bug introduced by
The property original_name does not seem to exist. Did you mean original?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
                return true;
28
            } else {
29
                return false;
30
            }
31
            /*if ($path = $file->storeAs('', $img_name,['visibility' => 'public'])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
                $attachment->name = $path;
33
                $attachment->original_name = $file->getClientOriginalName();
34
                return true;
35
            } else {
36
                return false;
37
            }*/
38
        }
39
    }
40
}
41