GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3df939...d640e4 )
by Mateusz
01:51
created

ExceptionFactory   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 86
Duplicated Lines 18.6 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 16
loc 86
ccs 28
cts 28
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A checkArgumentType() 0 9 2
A checkArgumentTypes() 0 10 3
A assertArgumentType() 8 8 2
A assertArgumentTypes() 8 8 2
A createInvalidArgumentException() 0 11 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
namespace NotificationChannels\Smsapi\Exceptions;
4
5
use InvalidArgumentException;
6
7
/**
8
 * @internal
9
 */
10
class ExceptionFactory
11
{
12
    /**
13
     * @param  string $expectedType
14
     * @param  mixed  $providedArgument
15
     * @return bool
16
     */
17 191
    public static function checkArgumentType($expectedType, $providedArgument)
18
    {
19 191
        $providedType = gettype($providedArgument);
20 191
        if ($providedType === 'object') {
21 36
            return is_a($providedArgument, $expectedType);
22
        } else {
23 170
            return $providedType === $expectedType;
24
        }
25
    }
26
27
    /**
28
     * @param  string[] $expectedTypes
29
     * @param  mixed    $providedArgument
30
     * @return bool
31
     */
32 103
    public static function checkArgumentTypes($expectedTypes, $providedArgument)
33
    {
34 103
        foreach ($expectedTypes as $expectedType) {
35 103
            if (self::checkArgumentType($expectedType, $providedArgument)) {
36 91
                return true;
37
            }
38
        }
39
40 18
        return false;
41
    }
42
43
    /**
44
     * @param  int    $argumentPosition
45
     * @param  string $function
46
     * @param  string $expectedType
47
     * @param  mixed  $providedArgument
48
     * @return void
49
     * @throws InvalidArgumentException
50
     */
51 159 View Code Duplication
    public static function assertArgumentType($argumentPosition, $function, $expectedType, $providedArgument)
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...
52
    {
53 159
        $ok = self::checkArgumentType($expectedType, $providedArgument);
54 159
        if (! $ok) {
55 120
            $providedType = gettype($providedArgument);
56 120
            throw self::createInvalidArgumentException($argumentPosition, $function, $expectedType, $providedType);
57
        }
58 39
    }
59
60
    /**
61
     * @param  int      $argumentPosition
62
     * @param  string   $function
63
     * @param  string[] $expectedTypes
64
     * @param  mixed    $providedArgument
65
     * @return void
66
     * @throws InvalidArgumentException
67
     */
68 103 View Code Duplication
    public static function assertArgumentTypes($argumentPosition, $function, $expectedTypes, $providedArgument)
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...
69
    {
70 103
        $ok = self::checkArgumentTypes($expectedTypes, $providedArgument);
71 103
        if (! $ok) {
72 18
            $providedType = gettype($providedArgument);
73 18
            throw self::createInvalidArgumentException($argumentPosition, $function, $expectedTypes, $providedType);
74
        }
75 91
    }
76
77
    /**
78
     * @param  int             $argumentPosition
79
     * @param  string          $function
80
     * @param  string|string[] $expectedType
0 ignored issues
show
Documentation introduced by
There is no parameter named $expectedType. Did you maybe mean $expectedTypes?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
81
     * @param  string          $providedTypes
0 ignored issues
show
Documentation introduced by
There is no parameter named $providedTypes. Did you maybe mean $providedType?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
82
     * @return InvalidArgumentException
83
     */
84 138
    public static function createInvalidArgumentException($argumentPosition, $function, $expectedTypes, $providedType)
85
    {
86 138
        if (! is_array($expectedTypes)) {
87 120
            $expectedTypes = [$expectedTypes];
88
        }
89
90 138
        return new InvalidArgumentException(sprintf(
91 138
            'Argument %d passed to %s() must be of the type %s, %s given',
92 138
            $argumentPosition, $function, implode(' or ', $expectedTypes), $providedType
93
        ));
94
    }
95
}
96