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

FieldHandleUpload::withMaxSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Akibatech\Crud\Traits;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Validation\Validator;
7
8
/**
9
 * Class FieldHandleUpload
10
 *
11
 * @package Akibatech\Crud\Traits
12
 */
13
trait FieldHandleUpload
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $disk = 'public';
19
20
    /**
21
     * @var string
22
     */
23
    protected $path = 'uploads';
24
25
    /**
26
     * @var string
27
     */
28
    protected $mimes;
29
30
    /**
31
     * @var int
32
     */
33
    protected $max_size;
34
35
    /**
36
     * @param   string $disk
37
     * @return  self
38
     */
39
    public function uploadToDisk($disk = 'public')
40
    {
41
        $this->disk = $disk;
42
43
        return $this;
44
    }
45
46
    /**
47
     * @param   string $path
48
     * @return  self
49
     */
50
    public function uploadToPath($path = 'uploads')
51
    {
52
        $this->path = $path;
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param   string $types
59
     * @return  self
60
     */
61
    public function withTypes($types)
62
    {
63
        $this->mimes = $types;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param   int $size
70
     * @return  self
71
     */
72
    public function withMaxSize($size = 2048)
73
    {
74
        $this->max_size = $size;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param   Validator $validator
81
     * @return  Validator
82
     */
83
    public function beforeValidation(Validator $validator)
84
    {
85
        $rules = [];
86
        $identifier = $this->getIdentifier();
0 ignored issues
show
Bug introduced by
It seems like getIdentifier() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
87
88
        if ($this->mimes)
89
        {
90
            $rules[] = 'mimes:' . $this->mimes;
91
        }
92
93
        if ($this->max_size)
94
        {
95
            $rules[] = 'max:' . $this->max_size;
96
        }
97
98
        if (count($rules) > 0)
99
        {
100
            $validator->sometimes($this->getIdentifier(), $rules, function ($input) use ($identifier)
0 ignored issues
show
Bug introduced by
It seems like getIdentifier() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
101
            {
102
                return is_null($input->{$identifier}) ? false : true;
103
            });
104
        }
105
106
        return $validator;
107
    }
108
}
109