Completed
Pull Request — master (#2)
by ARCANEDEV
08:47
created

RateCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
ccs 10
cts 12
cp 0.8333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFrom() 0 4 1
A setFrom() 0 6 1
A load() 0 11 2
1
<?php namespace Arcanedev\Currencies\Entities;
2
3
use Arcanedev\Support\Collection;
4
5
/**
6
 * Class     RateCollection
7
 *
8
 * @package  Arcanedev\Currencies\Entities
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class RateCollection extends Collection
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * @var string
19
     */
20
    protected $from;
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Getters & Setters
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * Get the `from` currency iso.
28
     *
29
     * @return string
30
     */
31
    public function getFrom()
32
    {
33
        return $this->from;
34
    }
35
36
    /**
37
     * Set the `from` currency iso.
38
     *
39
     * @param  string  $from
40
     *
41
     * @return self
42
     */
43 12
    public function setFrom($from)
44
    {
45 12
        $this->from = $from;
46
47 12
        return $this;
48
    }
49
50
    /* ------------------------------------------------------------------------------------------------
51
     |  Main Functions
52
     | ------------------------------------------------------------------------------------------------
53
     */
54
    /**
55
     * Load rates.
56
     *
57
     * @param  string  $from
58
     * @param  array   $rates
59
     *
60
     * @return static
61
     */
62 12
    public function load($from, array $rates)
63
    {
64 12
        $this->reset();
65 12
        $this->setFrom($from);
66
67 12
        foreach ($rates as $to => $ratio) {
68 12
            $this->put($to, Rate::make($from, $to, $ratio));
69 9
        }
70
71 12
        return $this;
72
    }
73
}
74