RoundTo   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 53
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A nearest() 0 6 1
A next() 0 6 1
A previous() 0 6 1
1
<?php
2
/**
3
 * Jnjxp Rinc
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  RoundTo
13
 * @package   Jnjxp\Rinc
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/jnjxp/jnjxp.rinc
18
 */
19
20
namespace Jnjxp\Rinc;
21
22
/**
23
 * RoundTo
24
 *
25
 * @category RoundTo
26
 * @package  Jnjxp\Rinc
27
 * @author   Jake Johns <[email protected]>
28
 * @license  http://jnj.mit-license.org/ MIT License
29
 * @link     https://github.com/jnjxp/jnjxp.rinc
30
 */
31
class RoundTo
32
{
33
    /**
34
     * Round to nearest increment
35
     *
36
     * @param float $increment incremenet to round to
37
     * @param float $value     value to round
38
     *
39
     * @return float
40
     *
41
     * @access public
42
     */
43 1
    public function nearest($increment, $value)
44
    {
45 1
        $value = $value / $increment;
46 1
        $value = round($value, 0);
47 1
        return $value * $increment;
48
    }
49
50
    /**
51
     * Round to next increment
52
     *
53
     * @param float $increment incremenet to round to
54
     * @param float $value     value to round
55
     *
56
     * @return float
57
     *
58
     * @access public
59
     */
60 1
    public function next($increment, $value)
61
    {
62 1
        $value = $value / $increment;
63 1
        $value = ceil($value);
64 1
        return $value * $increment;
65
    }
66
67
    /**
68
     * Round to previous increment
69
     *
70
     * @param float $increment incremenet to round to
71
     * @param float $value     value to round
72
     *
73
     * @return float
74
     *
75
     * @access public
76
     */
77 1
    public function previous($increment, $value)
78
    {
79 1
        $value = $value / $increment;
80 1
        $value = floor($value);
81 1
        return $value * $increment;
82
    }
83
}
84