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 ( b77b49...6ef5d2 )
by Cees-Jan
02:41
created

SecureLine::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 0
cp 0
rs 9.6667
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
3
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
4
5
class SecureLine implements LineInterface
6
{
7
    /**
8
     * @var Line
9
     */
10
    protected $line;
11
12
    /**
13
     * @var string
14
     */
15
    protected $key;
16
17
    /**
18
     * @param \JsonSerializable $line
19
     * @param array $options
20
     */
21 2
    public function __construct(\JsonSerializable $line, array $options)
22
    {
23 2
        $this->line = $line;
0 ignored issues
show
Documentation Bug introduced by
It seems like $line of type object<JsonSerializable> is incompatible with the declared type object<WyriHaximus\React...essenger\Messages\Line> of property $line.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24 2
        $this->key  = $options['key'];
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function __toString()
31
    {
32
        $line = json_encode($this->line);
33
        return json_encode([
34
            'type' => 'secure',
35
            'line' => $line,
36
            'signature' => base64_encode(static::sign($line, $this->key)),
37
        ]) . LineInterface::EOL;
38
    }
39
40
    protected static function sign($line, $key)
41
    {
42
        return hash_hmac('sha256', $line, $key, true);
43
    }
44
45
    protected static function validate($signature, $line, $key)
46
    {
47
        return hash_equals($signature, static::sign($line, $key));
48
    }
49
50 4
    public static function fromLine($line, array $lineOptions)
51
    {
52
        if (static::validate(base64_decode($line['signature']), $line['line'], $lineOptions['key'])) {
53
            return Factory::fromLine($line['line'], $lineOptions);
54
        }
55
56
        throw new \Exception('Signature mismatch!');
57 4
    }
58
}
59