CurrencyHelper::convert()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 4
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
}