Completed
Push — master ( 7b8b46...795e4b )
by ARCANEDEV
14:25
created

UnitsManager::fileSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\Units;
2
3
use Arcanedev\Support\Manager;
4
use Arcanedev\Units\Contracts\UnitsManager as UnitsManagerContract;
5
use Illuminate\Support\Arr;
6
use InvalidArgumentException;
7
8
/**
9
 * Class     UnitsManager
10
 *
11
 * @package  Arcanedev\Units
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class UnitsManager extends Manager implements UnitsManagerContract
15
{
16
    /* -----------------------------------------------------------------
17
     |  Main Methods
18
     | -----------------------------------------------------------------
19
     */
20
    /**
21
     * Create the distance unit driver.
22
     *
23
     * @return \Arcanedev\Units\Bases\UnitMeasure
24
     */
25 18
    protected function createDistanceDriver()
26
    {
27 18
        return $this->distance();
28
    }
29
30
    /**
31
     * Create the distance unit instance.
32
     *
33
     * @return \Arcanedev\Units\Bases\UnitMeasure
34
     */
35 18
    public function distance()
36
    {
37 18
        return $this->buildUnit('distance', Measures\Distance::class);
38
    }
39
40
    /**
41
     * Create the file size unit driver.
42
     *
43
     * @return \Arcanedev\Units\Bases\UnitMeasure
44
     */
45 9
    protected function createFileSizeDriver()
46
    {
47 9
        return $this->fileSize();
48
    }
49
50
    /**
51
     * Create the file size unit instance.
52
     *
53
     * @return \Arcanedev\Units\Bases\UnitMeasure
54
     */
55 9
    public function fileSize()
56
    {
57 9
        return $this->buildUnit('file-size', Measures\FileSize::class);
58
    }
59
60
    /**
61
     * Create the liquid volume unit driver.
62
     *
63
     * @return \Arcanedev\Units\Bases\UnitMeasure
64
     */
65 9
    protected function createLiquidVolumeDriver()
66
    {
67 9
        return $this->liquidVolume();
68
    }
69
70
    /**
71
     * Create the liquid volume unit instance.
72
     *
73
     * @return \Arcanedev\Units\Bases\UnitMeasure
74
     */
75 9
    public function liquidVolume()
76
    {
77 9
        return $this->buildUnit('liquid-volume', Measures\LiquidVolume::class);
78
    }
79
80
    /**
81
     * Create the weight unit driver.
82
     *
83
     * @return \Arcanedev\Units\Bases\UnitMeasure
84
     */
85 9
    protected function createWeightDriver()
86
    {
87 9
        return $this->weight();
88
    }
89
90
    /**
91
     * Create the weight unit instance.
92
     *
93
     * @return \Arcanedev\Units\Bases\UnitMeasure
94
     */
95 9
    public function weight()
96
    {
97 9
        return $this->buildUnit('weight', Measures\Weight::class);
98
    }
99
100
    /**
101
     * Get the default driver name.
102
     *
103
     * @return string
104
     */
105 9
    public function getDefaultDriver()
106
    {
107 9
        throw new InvalidArgumentException('No unit of measurement was specified.');
108
    }
109
110
    /* -----------------------------------------------------------------
111
     |  Other Methods
112
     | -----------------------------------------------------------------
113
     */
114
    /**
115
     * Build the unit of measurement.
116
     *
117
     * @param  string  $key
118
     * @param  string  $unitClass
119
     *
120
     * @return \Arcanedev\Units\Bases\UnitMeasure
121
     */
122 45
    protected function buildUnit($key, $unitClass)
123
    {
124 45
        $configs = $this->app['config']->get("units.$key", []);
125
126 45
        return new $unitClass(
127 45
            0, Arr::get($configs, 'default'), Arr::except($configs, ['default'])
128 15
        );
129
    }
130
}
131