NoSuchBindingException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 50%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forUuidAndModule() 8 8 1
A forUuid() 7 7 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\Discovery;
13
14
use Exception;
15
use Rhumsaa\Uuid\Uuid;
16
use RuntimeException;
17
18
/**
19
 * Thrown when a binding was not found.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25 View Code Duplication
class NoSuchBindingException 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...
26
{
27
    /**
28
     * Creates an exception for a UUID that was not found.
29
     *
30
     * @param Uuid           $uuid  The UUID.
31
     * @param Exception|null $cause The exception that caused this exception.
32
     *
33
     * @return static The created exception.
34
     */
35 4
    public static function forUuid(Uuid $uuid, Exception $cause = null)
36
    {
37 4
        return new static(sprintf(
38 4
            'The binding with UUID "%s" does not exist.',
39 4
            $uuid->toString()
40 4
        ), 0, $cause);
41
    }
42
43
    /**
44
     * Creates an exception for a UUID that was not found in a given module.
45
     *
46
     * @param Uuid           $uuid       The UUID.
47
     * @param string         $moduleName The name of the containing module.
48
     * @param Exception|null $cause      The exception that caused this
49
     *                                   exception.
50
     *
51
     * @return static The created exception.
52
     */
53
    public static function forUuidAndModule(Uuid $uuid, $moduleName, Exception $cause = null)
54
    {
55
        return new static(sprintf(
56
            'The binding with UUID "%s" does not exist in module "%s".',
57
            $uuid->toString(),
58
            $moduleName
59
        ), 0, $cause);
60
    }
61
}
62