Conversion::BTC_float2int()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4
/**
5
 * Short File Description
6
 *
7
 * PHP version 5
8
 *
9
 * @category   aCategory
10
 * @package    aPackage
11
 * @subpackage aSubPackage
12
 * @author     anAuthor
13
 * @copyright  2014 a Copyright
14
 * @license    a License
15
 * @link       http://www.aLink.com
16
 */
17
namespace Appino\Blockchain\Classes\Conversion;
18
19
/**
20
 * Short Class Description
21
 *
22
 * PHP version 5
23
 *
24
 * @category   aCategory
25
 * @package    aPackage
26
 * @subpackage aSubPackage
27
 * @author     anAuthor
28
 * @copyright  2014 a Copyright
29
 * @license    a License
30
 * @link       http://www.aLink.com
31
 */
32
class Conversion
33
{
34
    /**
35
     * Properties
36
     */
37
38
39
    /**
40
     * Methods
41
     */
42
    /**
43
     * Convert an incoming integer to a BTC string value
44
     */
45
    static function BTC_int2str($val)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
    {
47
        $a = bcmul($val, "1.0", 1);
48
        return bcdiv($a, "100000000", 8);
49
    }
50
51
    /**
52
     * Convert a float value to BTC satoshi integer string
53
     */
54
    static function BTC_float2int($val)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
    {
56
        return bcmul($val, "100000000", 0);
57
    }
58
59
    /**
60
     * From comment on http://php.net/manual/en/ref.bc.php
61
     */
62
    static function bcconv($fNumber)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
63
    {
64
        $sAppend = '';
65
        $iDecimals = ini_get('precision') - floor(log10(abs($fNumber)));
66
        if (0 > $iDecimals) {
67
            $fNumber *= pow(10, $iDecimals);
68
            $sAppend = str_repeat('0', -$iDecimals);
0 ignored issues
show
Bug introduced by
-$iDecimals of type double is incompatible with the type integer expected by parameter $multiplier of str_repeat(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
            $sAppend = str_repeat('0', /** @scrutinizer ignore-type */ -$iDecimals);
Loading history...
69
            $iDecimals = 0;
70
        }
71
72
        return number_format($fNumber, $iDecimals, '.', '').$sAppend;
0 ignored issues
show
Bug introduced by
It seems like $iDecimals can also be of type double; however, parameter $decimals of number_format() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        return number_format($fNumber, /** @scrutinizer ignore-type */ $iDecimals, '.', '').$sAppend;
Loading history...
73
    }
74
}
75