Completed
Push — master ( fc5bca...29537e )
by ARCANEDEV
16s
created

WithOptions   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 80
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1
ccs 13
cts 13
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 4 1
A getOption() 0 4 1
A setOptions() 0 6 1
A setOption() 0 6 1
A resetOptions() 0 6 1
1
<?php namespace Arcanedev\LaravelExcel\Traits;
2
3
use Illuminate\Support\Arr;
4
5
/**
6
 * Trait     WithOptions
7
 *
8
 * @package  Arcanedev\LaravelExcel\Traits
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
trait WithOptions
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
18
    protected $options = [];
19
20
    /* -----------------------------------------------------------------
21
     |  Main Methods
22
     | -----------------------------------------------------------------
23
     */
24
25
    /**
26
     * Get all the options.
27
     *
28
     * @return array
29
     */
30 93
    public function getOptions()
31
    {
32 93
        return $this->options;
33
    }
34
35
    /**
36
     * Get an option.
37
     *
38
     * @param  string  $key
39
     * @param  mixed   $default
40
     *
41
     * @return mixed
42
     */
43 18
    public function getOption($key, $default = null)
44
    {
45 18
        return Arr::get($this->getOptions(), $key, $default);
46
    }
47
48
    /**
49
     * Set the options.
50
     *
51
     * @param  array  $options
52
     *
53
     * @return self
54
     */
55 93
    public function setOptions(array $options)
56
    {
57 93
        return $this->resetOptions(
58 93
            array_merge($this->getOptions(), $options)
59
        );
60
    }
61
62
    /**
63
     * Set an option.
64
     *
65
     * @param  string  $key
66
     * @param  mixed   $value
67
     *
68
     * @return self
69
     */
70 36
    public function setOption($key, $value)
71
    {
72 36
        $this->options[$key] = $value;
73
74 36
        return $this;
75
    }
76
77
    /**
78
     * Reset the options.
79
     *
80
     * @param  array  $options
81
     *
82
     * @return self
83
     */
84 93
    public function resetOptions(array $options = [])
85
    {
86 93
        $this->options = $options;
87
88 93
        return $this;
89
    }
90
}
91