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 ( d2756c...fca21c )
by Mateusz
01:48
created

ExceptionFactory::createInvalidArgumentException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 4
crap 6
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
    public static function checkArgumentType($expectedType, $providedArgument)
18
    {
19
        $providedType = gettype($providedArgument);
20
        if ($providedType === 'object') {
21
            return is_a($providedArgument, $expectedType);
22
        } else {
23
            return $providedType === $expectedType;
24
        }
25
    }
26
27
    /**
28
     * @param  string[] $expectedTypes
29
     * @param  mixed    $providedArgument
30
     * @return bool
31
     */
32
    public static function checkArgumentTypes($expectedTypes, $providedArgument)
33
    {
34
        foreach ($expectedTypes as $expectedType) {
35
            if (self::checkArgumentType($expectedType, $providedArgument)) {
36
                return true;
37
            }
38
        }
39
        return false;
40
    }
41
42
    /**
43
     * @param  int    $argumentPosition
44
     * @param  string $function
45
     * @param  string $expectedType
46
     * @param  mixed  $providedArgument
47
     * @return void
48
     * @throws InvalidArgumentException
49
     */
50 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...
51
    {
52
        $ok = self::checkArgumentType($expectedType, $providedArgument);
53
        if (!$ok) {
54
            $providedType = gettype($providedArgument);
55
            throw self::createInvalidArgumentException($argumentPosition, $function, $expectedType, $providedType);
56
        }
57
    }
58
59
    /**
60
     * @param  int      $argumentPosition
61
     * @param  string   $function
62
     * @param  string[] $expectedTypes
63
     * @param  mixed    $providedArgument
64
     * @return void
65
     * @throws InvalidArgumentException
66
     */
67 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...
68
    {
69
        $ok = self::checkArgumentTypes($expectedTypes, $providedArgument);
70
        if (!$ok) {
71
            $providedType = gettype($providedArgument);
72
            throw self::createInvalidArgumentException($argumentPosition, $function, $expectedTypes, $providedType);
73
        }
74
    }
75
76
    /**
77
     * @param  int             $argumentPosition
78
     * @param  string          $function
79
     * @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...
80
     * @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...
81
     * @return InvalidArgumentException
82
     */
83
    public static function createInvalidArgumentException($argumentPosition, $function, $expectedTypes, $providedType)
84
    {
85
        if (!is_array($expectedTypes)) {
86
            $expectedTypes = [$expectedTypes];
87
        }
88
        return new InvalidArgumentException(sprintf(
89
            "Argument %d passed to %s() must be of the type %s, %s given",
90
            $argumentPosition, $function, implode(' or ', $expectedTypes), $providedType
91
        ));
92
    }
93
}