Completed
Push — master ( 6a43ea...7edb4c )
by Nikola
45:00
created

Rate::__construct()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 14
cts 14
cp 1
rs 9.4286
cc 3
eloc 12
nc 1
nop 8
crap 3

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace RunOpenCode\ExchangeRate\Model;
4
5
use RunOpenCode\ExchangeRate\Contract\RateInterface;
6
use RunOpenCode\ExchangeRate\Utils\CurrencyCodeUtil;
7
8
class Rate implements RateInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $sourceName;
14
15
    /**
16
     * @var float
17
     */
18
    protected $value;
19
20
    /**
21
     * @var string
22
     */
23
    protected $currencyCode;
24
25
    /**
26
     * @var string
27
     */
28
    protected $rateType;
29
30
    /**
31
     * @var \DateTime
32
     */
33
    protected $date;
34
35
    /**
36
     * @var string
37
     */
38
    protected $baseCurrencyCode;
39
40
    /**
41
     * @var \DateTime
42
     */
43
    protected $createdAt;
44
45
    /**
46
     * @var \DateTime
47
     */
48
    protected $modifiedAt;
49
50 12
    public function __construct($sourceName, $value, $currencyCode, $rateType, $date, $baseCurrencyCode, $createdAt = null, $modifiedAt = null)
51
    {
52 12
        $this->sourceName = $sourceName;
53 12
        $this->value = $value;
54 12
        $this->currencyCode = CurrencyCodeUtil::clean($currencyCode);
55 12
        $this->rateType = $rateType;
56 12
        $this->baseCurrencyCode = CurrencyCodeUtil::clean($baseCurrencyCode);
57
58 12
        $processDate = function($arg) {
59 12
            $arg = (is_null($arg)) ? new \DateTime('now') : $arg;
60 12
            return (is_numeric($arg)) ? date_timestamp_set(new \DateTime(), $arg) : clone $arg;
61 12
        };
62
63 12
        $this->date = $processDate($date);
64 12
        $this->createdAt = $processDate($createdAt);
65 12
        $this->modifiedAt = $processDate($modifiedAt);
66 12
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 4
    public function getSourceName()
72
    {
73 4
        return $this->sourceName;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 4
    public function getValue()
80
    {
81 4
        return $this->value;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 6
    public function getCurrencyCode()
88
    {
89 6
        return $this->currencyCode;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 6
    public function getRateType()
96
    {
97 6
        return $this->rateType;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 4
    public function getDate()
104
    {
105 4
        return ($this->date) ? clone $this->date : null;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 2
    public function getBaseCurrencyCode()
112
    {
113 2
        return $this->baseCurrencyCode;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119 2
    public function getCreatedAt()
120
    {
121 2
        return clone $this->createdAt;
122
    }
123
124
    /**
125
     * {@inheritdoc}
126
     */
127 2
    public function getModifiedAt()
128
    {
129 2
        return clone $this->modifiedAt;
130
    }
131
}
132