ccn_function.php ➔ ccn_function()   C
last analyzed

Complexity

Conditions 12
Paths 11

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
cc 12
nc 11
nop 1
dl 32
loc 32
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
/**
19
 * Test function with a high cyclomatic complexity
20
 */
21 View Code Duplication
function ccn_function($arg)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
{
23
    switch ($arg) {
24
        case 1:
25
            for ($i = 0; $i < 10; ++$i) {
26
                if ($i % 2 === 0) {
27
                    if ($arg - $i < 0) {
28
                        echo "foo";
29
                    }
30
                }
31
            }
32
            break;
33
        case 2:
34
            while (true) {
35
                if (time() % 5 === 0 && time() % 2 === 0) {
36
                    break;
37
                } else {
38
                    if (time() % 7 === 0) {
39
                        $x = true;
40
                        for ($i = 0; $i < 42; ++$i) {
41
                            $x = $x || true;
42
                        }
43
44
                        return $x;
45
                    }
46
                }
47
48
                return 23;
49
            }
50
            break;
51
    }
52
}
53