Completed
Push — master ( 8507e2...2d694e )
by Lars
01:39
created

TypeCheckSimple::throwException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arrayy\TypeCheck;
6
7
final class TypeCheckSimple extends AbstractTypeCheck implements TypeCheckInterface
8
{
9
    /**
10
     * @param string|string[] $type
11
     * @param bool            $isNullable
12
     */
13 72
    public function __construct($type, bool $isNullable = false)
14
    {
15 72
        if (\is_array($type)) {
16 2
            foreach ($type as $typeTmp) {
17 2
                $this->types[] = $typeTmp;
18
            }
19
        } else {
20 72
            $this->types[] = $type;
21
        }
22
23 72
        $this->isNullable = $isNullable;
24 72
    }
25
26
    /**
27
     * @param string $expectedTypes
28
     * @param mixed  $value
29
     * @param string $type
30
     *
31
     * @return \TypeError
32
     */
33 21
    public function throwException($expectedTypes, $value, $type): \Throwable
34
    {
35 21
        throw new \TypeError("Invalid type: expected to be of type {{$expectedTypes}}, instead got value `" . \print_r($value, true) . "` with type {{$type}}.");
0 ignored issues
show
Unused Code introduced by
The call to TypeError::__construct() has too many arguments starting with "Invalid type: expected ...` with type {{$type}}.".

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
36
    }
37
}
38