Completed
Push — master ( aaf903...420502 )
by Marcos
03:15
created

IncomparableException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A forType() 12 12 2

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 phpcommon/comparison package.
5
 *
6
 * (c) Marcos Passos <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace PhpCommon\Comparison;
13
14
use InvalidArgumentException;
15
use Exception;
16
17
/**
18
 * Thrown when values provided for comparison are incomparable.
19
 *
20
 * @author Marcos Passos <[email protected]>
21
 */
22 View Code Duplication
class IncomparableException extends InvalidArgumentException
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...
23
{
24
    /**
25
     * Creates a new exception for the given value type.
26
     *
27
     * @param string         $type  The name of the expected type.
28
     * @param mixed          $value The specified value.
29
     * @param int            $code  The exception code.
30
     * @param Exception|null $cause The exception that caused this exception.
31
     *
32
     * @return UnexpectedTypeException The new exception.
33
     */
34 4
    public static function forType($type, $value, $code = 0, Exception $cause = null)
35
    {
36 4
        return new self(
37 4
            sprintf(
38 4
                'Unable to compare "%s" with "%s".',
39 4
                $type,
40 4
                is_object($value) ? get_class($value) : gettype($value)
41 4
            ),
42 4
            $code,
43
            $cause
44 4
        );
45
    }
46
}
47