Passed
Push — master ( e7798d...4b26b6 )
by Mikhail
02:39
created

ParserException::unexpectedCollectorReturn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace JsonDecodeStream\Exception;
5
6
use JsonDecodeStream\Event;
7
use JsonDecodeStream\Token;
8
9
class ParserException extends JsonDecodeStreamException
10
{
11
    const CODE_INVALID_ARGUMENT = 1;
12
    const CODE_UNEXPECTED_VALUE = 2;
13
14
    const CODE_UNEXPECTED_TOKEN = 101;
15
    const CODE_EXPECTED_BUT_GOT = 102;
16
17
    public function __construct($message, int $code, ?int $lineNumber = null, ?int $charNumber = null)
18
    {
19
        if ($lineNumber !== null && $charNumber !== null) {
20
            $message .= " at $lineNumber:$charNumber";
21
        }
22
        parent::__construct($message, $code);
23
    }
24
25
    public static function unexpectedToken(Token $token)
26
    {
27
        return new static(
28
            sprintf('Unexpected token `%s`', $token->getId()),
29
            static::CODE_UNEXPECTED_TOKEN,
30
            $token->getLineNumber(), $token->getCharNumber()
31
        );
32
    }
33
34
    public static function expectedButGot(string $expected, Token $gotToken)
35
    {
36
        $got = ($gotToken->getValue() ? json_encode($gotToken->getValue()) : $gotToken->getId());
37
        return new static(
38
            sprintf('Expected `%s` but got `%s`', $expected, $got),
39
            static::CODE_EXPECTED_BUT_GOT,
40
            $gotToken->getLineNumber(), $gotToken->getCharNumber()
41
        );
42
    }
43
44
    public static function unexpectedCollectorReturn($yielded, Event $event)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public static function unexpectedCollectorReturn($yielded, /** @scrutinizer ignore-unused */ Event $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $yielded is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

44
    public static function unexpectedCollectorReturn(/** @scrutinizer ignore-unused */ $yielded, Event $event)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
47
    }
48
}
49