GCD   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 9
c 3
b 2
f 0
lcom 0
cbo 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getGCD() 0 20 6
A isInteger() 0 11 3
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
13
namespace Thelia\Math;
14
15
/**
16
 * Class GCD
17
 * @package Thelia\Math
18
 * @author Benjamin Perche <[email protected]>
19
 */
20
class GCD
21
{
22
    public static function getGCD($numberA, $numberB)
23
    {
24
        if (! self::isInteger($numberA) | ! self::isInteger($numberB)) {
25
            throw new \InvalidArgumentException(
26
                "GCD number must be an integer"
27
            );
28
        }
29
30
        if (function_exists("gmp_gcd")) {
31
            return gmp_intval(gmp_gcd($numberA, $numberB));
32
        }
33
34
        if ($numberA == 0 || $numberB == 0) {
35
            return max(abs($numberA), abs($numberB));
36
        }
37
        
38
        $r = $numberA % $numberB;
39
40
        return ($r != 0) ? self::getGCD($numberB, $r) : abs($numberB);
41
    }
42
43
    public static function isInteger($var)
44
    {
45
        if (is_int($var)) {
46
            // the most obvious test
47
            return true;
48
        } elseif (is_numeric($var)) {
49
            // cast to string first
50
            return ctype_digit((string)$var);
51
        }
52
        return false;
53
    }
54
}
55