NonRootModuleExpectedException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A cannotEnableBinding() 9 9 1
A cannotDisableBinding() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the puli/manager package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Manager\Api;
13
14
use Exception;
15
use Rhumsaa\Uuid\Uuid;
16
use RuntimeException;
17
18
/**
19
 * Thrown when an operation was performed for the root module when a non-root
20
 * module was expected.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26 View Code Duplication
class NonRootModuleExpectedException extends RuntimeException
0 ignored issues
show
Duplication introduced by
This class 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...
27
{
28
    /**
29
     * Creates an exception for a binding UUID that could not be enabled in the
30
     * root module.
31
     *
32
     * @param Uuid           $uuid       The UUID.
33
     * @param string         $moduleName The name of the module.
34
     * @param Exception|null $cause      The exception that caused this
35
     *                                   exception.
36
     *
37
     * @return static The created exception.
38
     */
39 1
    public static function cannotEnableBinding(Uuid $uuid, $moduleName, Exception $cause = null)
40
    {
41 1
        return new static(sprintf(
42
            'Cannot enable binding "%s" in module "%s": Can only enable '.
43 1
            'bindings in non-root modules.',
44 1
            $uuid->toString(),
45
            $moduleName
46 1
        ), 0, $cause);
47
    }
48
49
    /**
50
     * Creates an exception for a binding UUID that could not be disabled in the
51
     * root module.
52
     *
53
     * @param Uuid           $uuid       The UUID.
54
     * @param string         $moduleName The name of the module.
55
     * @param Exception|null $cause      The exception that caused this
56
     *                                   exception.
57
     *
58
     * @return static The created exception.
59
     */
60 1
    public static function cannotDisableBinding(Uuid $uuid, $moduleName, Exception $cause = null)
61
    {
62 1
        return new static(sprintf(
63
            'Cannot disable binding "%s" in module "%s": Can only disable '.
64 1
            'bindings in non-root modules.',
65 1
            $uuid->toString(),
66
            $moduleName
67 1
        ), 0, $cause);
68
    }
69
}
70