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 ( 22b6cf...443b3e )
by Patrique
04:42
created

StreamFactory::createStreamFromResource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Patoui\Router;
6
7
use Psr\Http\Message\StreamFactoryInterface;
8
use Psr\Http\Message\StreamInterface;
9
use RuntimeException;
10
11
final class StreamFactory implements StreamFactoryInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function createStream(string $content = ''): StreamInterface
17
    {
18
        $resource = fopen(Stream::TEMPORARY_STREAM, 'rb+');
19
20
        if ($resource === false) {
21
            throw new RuntimeException('Unabled to open temporary resource');
22
        }
23
24
        fwrite($resource, $content);
25
        rewind($resource);
26
27
        return new Stream($resource);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function createStreamFromFile(string $filename, string $mode = 'rb'): StreamInterface
34
    {
35
        $stream = fopen($filename, $mode);
36
37
        if ($stream === false) {
38
            throw new RuntimeException("Unable to open file: {$filename}");
39
        }
40
41
        return new Stream($stream);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function createStreamFromResource($resource): StreamInterface
48
    {
49
        /** @psalm-suppress DocblockTypeContradiction */
50
        if (!is_resource($resource)) {
51
            throw new \InvalidArgumentException('Invalid resource, cannot create stream.');
52
        }
53
54
        return new Stream($resource);
55
    }
56
}
57