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

RateCollection::getFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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