Completed
Pull Request — master (#2)
by ARCANEDEV
02:44
created

Rate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php namespace Arcanedev\Currencies\Entities;
2
use Illuminate\Contracts\Support\Arrayable;
3
use Illuminate\Contracts\Support\Jsonable;
4
5
/**
6
 * Class     Rate
7
 *
8
 * @package  Arcanedev\Currencies\Entities
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class Rate implements Arrayable, Jsonable
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * @var string
19
     */
20
    public $from;
21
22
    /**
23
     * @var string
24
     */
25
    public $to;
26
27
    /**
28
     * @var double
29
     */
30
    public $ratio;
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Constructor
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Rate constructor.
38
     *
39
     * @param  string  $from
40
     * @param  string  $to
41
     * @param  double  $ratio
42
     */
43
    public function __construct($from, $to, $ratio)
44
    {
45
        $this->from  = $from;
46
        $this->to    = $to;
47
        $this->ratio = $ratio;
48
    }
49
50
    /* ------------------------------------------------------------------------------------------------
51
     |  Main Functions
52
     | ------------------------------------------------------------------------------------------------
53
     */
54
    /**
55
     * Make a rate instance.
56
     *
57
     * @param  string  $from
58
     * @param  string  $to
59
     * @param  double  $ratio
60
     *
61
     * @return self
62
     */
63
    public static function make($from, $to, $ratio)
64
    {
65
        return new self($from, $to, $ratio);
66
    }
67
68
    /**
69
     * Get the instance as an array.
70
     *
71
     * @return array
72
     */
73
    public function toArray()
74
    {
75
        return [
76
            'from'  => $this->from,
77
            'to'    => $this->to,
78
            'ratio' => $this->ratio,
79
        ];
80
    }
81
82
    /**
83
     * Convert the object to its JSON representation.
84
     *
85
     * @param  int $options
86
     * @return string
87
     */
88
    public function toJson($options = 0)
89
    {
90
        return json_encode($this->toArray(), $options);
91
    }
92
}
93