GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Push — master ( 659f53...df9043 )
by Peng
03:26
created

CurrencyWebservice::getExchangeRate()   C

Complexity

Conditions 14
Paths 26

Size

Total Lines 59
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 49
nc 26
nop 2
dl 0
loc 59
rs 6.4055
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Awin\ReportTask\Bundle\ReportBundle\Model;
4
5
use Awin\ReportTask\Bundle\ReportBundle\Exception\CurrencyExchangeRateNotFoundException;
6
7
/**
8
 * The fake currency webservice, the currency exchange rate betweem 2 currencies are random,
9
 * Ideally this class should be a service, rather than a model, according to the requirement, keep it in model for now
10
 *
11
 * @date       24/06/2017
12
 * @time       11:35
13
 * @author     Peng Yue <[email protected]>
14
 * @copyright  2004-2017 Peng Yue
15
 */
16
17
class CurrencyWebservice
18
{
19
    /**
20
     * Return random value here for basic currencies like GBP USD EUR (simulates real API)
21
     * @param string $originalCurrency
22
     * @param string $targetCurrency
23
     *
24
     * @return float
25
     */
26
    public function getExchangeRate($originalCurrency, $targetCurrency)
27
    {
28
        $rate = null;
29
30
        switch ($originalCurrency) {
31
            case 'GBP':
32
                switch($targetCurrency) {
33
                    case 'GBP':
34
                        $rate = 1.00;
35
                        break;
36
                    case 'USD':
37
                        $rate = random_int(124, 139) / 100;
38
                        break;
39
                    case 'EUR':
40
                        $rate = random_int(111, 115) / 100;
41
                        break;
42
                    default:
43
                        break;
44
                }
45
                break;
46
            case 'USD':
47
                switch($targetCurrency) {
48
                    case 'GBP':
49
                        $rate = random_int(77, 82) / 100;
50
                        break;
51
                    case 'USD':
52
                        $rate = 1.00;
53
                        break;
54
                    case 'EUR':
55
                        $rate = random_int(87, 92) / 100;
56
                        break;
57
                    default:
58
                        break;
59
                }
60
                break;
61
            case 'EUR':
62
                switch($targetCurrency) {
63
                    case 'GBP':
64
                        $rate = random_int(85, 90) / 100;
65
                        break;
66
                    case 'USD':
67
                        $rate = random_int(109, 114) / 100;
68
                        break;
69
                    case 'EUR':
70
                        $rate = 1.00;
71
                        break;
72
                    default:
73
                        break;
74
                }
75
                break;
76
            default:
77
                break;
78
        }
79
80
        if (null == $rate) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $rate of type null|integer against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
81
            throw new CurrencyExchangeRateNotFoundException($originalCurrency, $targetCurrency);
82
        }
83
84
        return (float)$rate;
85
    }
86
}