Completed
Push — master ( b286ff...53e76c )
by Adrian
04:28
created

HasUploadTrait   F

Complexity

Total Complexity 91

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 91
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 76
ccs 12
cts 15
cp 0.8
rs 1.5789

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUploadContainer() 0 4 2
A setUploadContainer() 0 6 1
A getUploadOptions() 0 4 2
A getUploadRules() 0 4 2
A setUploadRules() 0 6 1
A setUploadOptions() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like HasUploadTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use HasUploadTrait, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Sirius\Input\Traits;
4
5
use Sirius\Input\Specs;
6
7
trait HasUploadTrait
8
{
9
10
    /**
11
     * Returns the upload container for the element
12
     *
13
     * @return null|mixed
14
     */
15 1
    function getUploadContainer()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
16
    {
17 1
        return isset($this[Specs::UPLOAD_CONTAINER]) ? $this[Specs::UPLOAD_CONTAINER] : null;
18
    }
19
20
    /**
21
     * Sets the upload container for the elment
22
     *
23
     * @param string|\Sirius\Upload\Container\ContainerInterface $container
24
     *
25
     * @return $this
26
     */
27 1
    function setUploadContainer($container)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
    {
29 1
        $this[Specs::UPLOAD_CONTAINER] = $container;
30
31 1
        return $this;
32
    }
33
34
    /**
35
     * Get the upload options (overwrite, auto confirm, etc)
36
     *
37
     * @see \Sirius\Upload\Handler
38
     * @return null|array
39
     */
40 1
    function getUploadOptions()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
    {
42 1
        return isset($this[Specs::UPLOAD_OPTIONS]) ? $this[Specs::UPLOAD_OPTIONS] : null;
43
    }
44
45
    /**
46
     * Get the upload options (overwrite, auto confirm, etc)
47
     *
48
     * @param array $options
49
     *
50
     * @return $this
51
     */
52
    function setUploadOptions($options = array())
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
    {
54
        $this[Specs::UPLOAD_OPTIONS] = $options;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Get the validation rules for the uploaded file(s)
61
     *
62
     * @return null|array
63
     */
64 1
    function getUploadRules()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
65
    {
66 1
        return isset($this[Specs::UPLOAD_RULES]) ? $this[Specs::UPLOAD_RULES] : null;
67
    }
68
69
    /**
70
     * Sets the validation rules for the uploaded file(s)
71
     *
72
     * @param array $rules
73
     *
74
     * @return $this
75
     */
76 1
    function setUploadRules($rules = array())
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
77
    {
78 1
        $this[Specs::UPLOAD_RULES] = $rules;
79
80 1
        return $this;
81
    }
82
}
83