Issues (83)

src/Util/Math.php (1 issue)

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