CurrencyHelper   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the Country Currency Converter
5
 *
6
 * (c) Nexuslink Services
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CountryCurrencyConverter\src\Services;
13
14
class CurrencyHelper {
15
    
16
    /**
17
     * 
18
     * @param string $from
19
     * @param string $to
20
     * @param int    $amount [optional]
21
     * @param bool   $round [optional]     
22
     * 
23
     * @return float
24
     */
25
    public static function convert($from, $to, $amount, $round) {
26
        
27
        $params = "a=".urlencode($amount)."&from=".urlencode($from)."&to=".urlencode($to);        
28
        $get = file_get_contents("https://www.google.com/finance/converter?".$params);
29
        $get = explode("<span class=bld>",$get);
30
        $get = explode("</span>",$get[1]);  
31
        $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
32
        
33
        return ($round ? number_format($converted_amount, 2) : $converted_amount);
34
    }
35
    
36
}