Passed
Pull Request — master (#2)
by Florian
02:55
created

ZendStreamFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 30
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 7 1
A createStreamFromFile() 0 5 1
A createStreamFromResource() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Copyright (c) Phauthentic (https://github.com/Phauthentic)
5
 *
6
 * Licensed under The MIT License
7
 * For full copyright and license information, please see the LICENSE.txt
8
 * Redistributions of files must retain the above copyright notice.
9
 *
10
 * @copyright     Copyright (c) Phauthentic (https://github.com/Phauthentic)
11
 * @link          https://github.com/Phauthentic
12
 * @license       https://opensource.org/licenses/mit-license.php MIT License
13
 */
14
namespace Phauthentic\Authentication\HttpFactory;
15
16
use Psr\Http\Message\StreamFactoryInterface;
17
use Psr\Http\Message\StreamInterface;
18
use Zend\Diactoros\Stream;
19
20
/**
21
 * Zend Stream Factory
22
 */
23
class ZendStreamFactory implements StreamFactoryInterface
24
{
25
    /**
26
     * @inheritdoc
27
     */
28
    public function createStream(string $content = ''): StreamInterface
29
    {
30
        $resource = fopen('php://memory', 'rw');
31
        fwrite($resource, $content);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        fwrite(/** @scrutinizer ignore-type */ $resource, $content);
Loading history...
32
        rewind($resource);
0 ignored issues
show
Bug introduced by
It seems like $resource can also be of type false; however, parameter $handle of rewind() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

32
        rewind(/** @scrutinizer ignore-type */ $resource);
Loading history...
33
34
        return $this->createStreamFromResource($resource);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
41
    {
42
        $resource = fopen($file, $mode);
43
44
        return $this->createStreamFromResource($resource);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function createStreamFromResource($resource): StreamInterface
51
    {
52
        return new Stream($resource);
53
    }
54
}
55