Math   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDiffInPercent() 0 10 2
1
<?php
2
namespace phpbu\App\Util;
3
4
/**
5
 * Math Util class
6
 *
7
 * @package    phpbu
8
 * @subpackage Util
9
 * @author     Sebastian Feldmann <[email protected]>
10
 * @copyright  Sebastian Feldmann <[email protected]>
11
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
12
 * @link       https://phpbu.de/
13
 * @since      Class available since Release 1.0.0
14
 */
15
class Math
16
{
17
    /**
18
     * Calculates the difference of two values in percent
19
     *
20
     * @param  int $a
21
     * @param  int $b
22
     * @return int
23
     */
24 7
    public static function getDiffInPercent(int $a, int $b) : int
25
    {
26 7
        if ($a > $b) {
27 5
            $whole = $a;
28 5
            $part  = $b;
29
        } else {
30 2
            $whole = $b;
31 2
            $part  = $a;
32
        }
33 7
        return 100 - ceil(($part / $whole) * 100);
0 ignored issues
show
Bug Best Practice introduced by
The expression return 100 - ceil($part / $whole * 100) returns the type double which is incompatible with the type-hinted return integer.
Loading history...
34
    }
35
}
36