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.

CurrencyWebservice::getExchangeRate()   C
last analyzed

Complexity

Conditions 14
Paths 26

Size

Total Lines 59
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 14.0543

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 49
c 1
b 0
f 0
nc 26
nop 2
dl 0
loc 59
ccs 43
cts 46
cp 0.9348
crap 14.0543
rs 6.2666

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 20
    public function getExchangeRate($originalCurrency, $targetCurrency)
27
    {
28 20
        $rate = null;
29
30 20
        switch ($originalCurrency) {
31 20
            case 'GBP':
32 7
                switch($targetCurrency) {
33 7
                    case 'GBP':
34 3
                        $rate = 1.00;
35 3
                        break;
36 5
                    case 'USD':
37 3
                        $rate = random_int(124, 139) / 100;
38 3
                        break;
39 3
                    case 'EUR':
40 3
                        $rate = random_int(111, 115) / 100;
41 3
                        break;
42
                    default:
43
                        break;
44
                }
45 7
                break;
46 14
            case 'USD':
47 7
                switch($targetCurrency) {
48 7
                    case 'GBP':
49 3
                        $rate = random_int(77, 82) / 100;
50 3
                        break;
51 5
                    case 'USD':
52 3
                        $rate = 1.00;
53 3
                        break;
54 3
                    case 'EUR':
55 3
                        $rate = random_int(87, 92) / 100;
56 3
                        break;
57
                    default:
58
                        break;
59
                }
60 7
                break;
61 8
            case 'EUR':
62 7
                switch($targetCurrency) {
63 7
                    case 'GBP':
64 3
                        $rate = random_int(85, 90) / 100;
65 3
                        break;
66 5
                    case 'USD':
67 3
                        $rate = random_int(109, 114) / 100;
68 3
                        break;
69 3
                    case 'EUR':
70 3
                        $rate = 1.00;
71 3
                        break;
72
                    default:
73
                        break;
74
                }
75 7
                break;
76
            default:
77 1
                break;
78
        }
79
80 20
        if (null === $rate) {
81 1
            throw new CurrencyExchangeRateNotFoundException($originalCurrency, $targetCurrency);
82
        }
83
84 19
        return (float)$rate;
85
    }
86
}