Completed
Push — master ( d0a026...e68bee )
by ARCANEDEV
14s queued 11s
created

HasRoundedValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 59
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A precision() 0 7 1
A roundValue() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelMetrics\Metrics\Concerns;
6
7
/**
8
 * Trait     HasRoundedValue
9
 *
10
 * @package  Arcanedev\LaravelMetrics\Metrics\Concerns
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
trait HasRoundedValue
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Rounding precision.
22
     *
23
     * @var int
24
     */
25
    public $roundingPrecision = 0;
26
27
    /**
28
     * Rounding mode.
29
     *
30
     * @var int
31
     */
32
    public $roundingMode = PHP_ROUND_HALF_UP;
33
34
    /* -----------------------------------------------------------------
35
     |  Getters & Setters
36
     | -----------------------------------------------------------------
37
     */
38
39
    /**
40
     * Set the precision level used when rounding the value.
41
     *
42
     * @param  int  $precision
43
     * @param  int  $mode
44
     *
45
     * @return $this
46
     */
47 2
    public function precision($precision = 0, $mode = PHP_ROUND_HALF_UP)
48
    {
49 2
        $this->roundingPrecision = $precision;
50 2
        $this->roundingMode      = $mode;
51
52 2
        return $this;
53
    }
54
55
    /* -----------------------------------------------------------------
56
     |  Main Methods
57
     | -----------------------------------------------------------------
58
     */
59
60
    /**
61
     * Round the value.
62
     *
63
     * @param  int|float  $value
64
     *
65
     * @return float
66
     */
67 28
    public function roundValue($value)
68
    {
69 28
        return round($value, $this->roundingPrecision, $this->roundingMode);
70
    }
71
}
72