AMQPDecimal   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A asBCvalue() 0 6 1
A getE() 0 3 1
A getN() 0 3 1
1
<?php
2
3
namespace PhpAmqpLib\Wire;
4
5
use PhpAmqpLib\Exception\AMQPOutOfBoundsException;
6
use PhpAmqpLib\Helper\BigInteger;
7
8
/**
9
 * AMQP protocol decimal value.
10
 *
11
 * Values are represented as (n,e) pairs. The actual value
12
 * is n * 10^(-e).
13
 *
14
 * From 0.8 spec: Decimal values are
15
 * not intended to support floating point values, but rather
16
 * business values such as currency rates and amounts. The
17
 * 'decimals' octet is not signed.
18
 */
19
class AMQPDecimal
20
{
21
    /** @var int */
22
    protected $n;
23
24
    /** @var int */
25
    protected $e;
26
27
    /**
28
     * @param int $n
29
     * @param int $e
30
     * @throws \PhpAmqpLib\Exception\AMQPOutOfBoundsException
31
     */
32 4
    public function __construct($n, $e)
33
    {
34 4
        if ($e < 0) {
35 1
            throw new AMQPOutOfBoundsException('Decimal exponent value must be unsigned!');
36
        }
37
38 3
        $this->n = $n;
39 3
        $this->e = $e;
40
    }
41
42
    /**
43
     * @return string
44
     */
45 1
    public function asBCvalue()
46
    {
47 1
        $n = new BigInteger($this->n);
48 1
        $e = new BigInteger('1' . str_repeat('0', $this->e));
49 1
        list($q) = $n->divide($e);
50 1
        return $q->toString();
51
    }
52
53
    /**
54
     * @return int
55
     */
56 1
    public function getE()
57
    {
58 1
        return $this->e;
59
    }
60
61
    /**
62
     * @return int
63
     */
64 1
    public function getN()
65
    {
66 1
        return $this->n;
67
    }
68
}
69