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.
Completed
Push — master ( ca95e4...2437e1 )
by Marceau
06:05
created

FileUploadField::getTableValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Akibatech\Crud\Fields;
4
5
use Akibatech\Crud\Traits\FieldHandleUpload;
6
use Illuminate\Http\UploadedFile;
7
8
/**
9
 * Class FileUploadField
10
 *
11
 * @package Akibatech\Crud\Fields
12
 */
13
class FileUploadField extends Field
14
{
15
    use FieldHandleUpload;
16
    
17
    /**
18
     * @var string
19
     */
20
    const TYPE = 'fileupload';
21
22
    /**
23
     * @var string
24
     */
25
    const MULTIPART = true;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function getViewName()
31
    {
32
        return 'crud::fields.fileupload';
33
    }
34
35
    /**
36
     * @param   mixed $file
37
     * @return  self
38
     */
39
    public function newValue($file)
40
    {
41
        if ($file instanceof UploadedFile)
42
        {
43
            $value = $file->store($this->path, $this->disk);
44
45
            $this->fields->getEntry()->getModel()->setAttribute($this->getIdentifier(), $value);
0 ignored issues
show
Bug introduced by
The method setAttribute does only exist in Illuminate\Database\Eloquent\Model, but not in Akibatech\Crud\Traits\Crudable.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
46
        }
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param   void
53
     * @return  string
54
     */
55
    public function getTableValue()
56
    {
57
        $value = $this->getValue();
58
59
        return empty($value) ? '' : sprintf('<a href="%s" target="_blank">%s</a>', url($value), basename($value));
60
    }
61
}
62