InvalidArgumentException   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 58 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 29
loc 50
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromInvalidType() 7 7 2
A fromEmptyKey() 0 4 1
A fromNonIterableKeys() 7 7 2
A fromNonIterableValues() 7 7 2
A fromKeyAndInvalidTTL() 8 8 2
A fromInvalidKeyCharacters() 0 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
declare(strict_types = 1);
3
4
namespace Roave\DoctrineSimpleCache\Exception;
5
6
class InvalidArgumentException
7
    extends \InvalidArgumentException
8
    implements \Psr\SimpleCache\InvalidArgumentException
9
{
10 2 View Code Duplication
    public static function fromKeyAndInvalidTTL(string $key, $ttl) : self
0 ignored issues
show
Duplication introduced by
This method 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...
11
    {
12 2
        return new self(sprintf(
13 2
            'TTL for "%s" should be defined by an integer or a DateInterval, but %s is given.',
14
            $key,
15 2
            is_object($ttl) ? get_class($ttl) : gettype($ttl)
16
        ));
17
    }
18
19 1
    public static function fromInvalidKeyCharacters(string $invalidKey) : self
20
    {
21 1
        return new self(sprintf(
22 1
            'Key "%s" is in an invalid format - must not contain characters: {}()/\@:',
23
            $invalidKey
24
        ));
25
    }
26
27 1 View Code Duplication
    public static function fromInvalidType($invalidKey) : self
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29 1
        return new self(sprintf(
30 1
            'Key was not a valid type. Expected string, received %s',
31 1
            is_object($invalidKey) ? get_class($invalidKey) : gettype($invalidKey)
32
        ));
33
    }
34
35 1
    public static function fromEmptyKey() : self
36
    {
37 1
        return new self('Requested key was an empty string.');
38
    }
39
40 1 View Code Duplication
    public static function fromNonIterableKeys($invalidKeys) : self
0 ignored issues
show
Duplication introduced by
This method 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...
41
    {
42 1
        return new self(sprintf(
43 1
            'Keys passed were not iterable (i.e. \Traversable or array), received: %s',
44 1
            is_object($invalidKeys) ? get_class($invalidKeys) : gettype($invalidKeys)
45
        ));
46
    }
47
48 1 View Code Duplication
    public static function fromNonIterableValues($invalidValues) : self
0 ignored issues
show
Duplication introduced by
This method 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...
49
    {
50 1
        return new self(sprintf(
51 1
            'Values passed were not iterable (i.e. \Traversable or array), received: %s',
52 1
            is_object($invalidValues) ? get_class($invalidValues) : gettype($invalidValues)
53
        ));
54
    }
55
}
56