MissingParameterException   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A forParameterName() 8 8 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/discovery 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\Discovery\Api\Type;
13
14
use Exception;
15
use RuntimeException;
16
17
/**
18
 * Thrown when a binding parameter is missing.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24 View Code Duplication
class MissingParameterException extends RuntimeException
25
{
26
    /**
27
     * Creates a new exception for the given parameter name.
28
     *
29
     * @param string         $parameterName The name of the parameter that was
30
     *                                      missing.
31
     * @param string         $typeName      The name of the type that the
32
     *                                      parameter was searched on.
33
     * @param Exception|null $cause         The exception that caused this
34
     *                                      exception.
35
     *
36
     * @return static The created exception.
37
     */
38 1
    public static function forParameterName($parameterName, $typeName, Exception $cause = null)
39
    {
40 1
        return new static(sprintf(
41 1
            'The parameter "%s" is required for type "%s".',
42
            $parameterName,
43
            $typeName
44 1
        ), 0, $cause);
45
    }
46
}
47