Completed
Push — master ( 2b82a4...1acfba )
by Oscar
02:59
created

StreamTrait::createStream()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
namespace Psr7Middlewares\Utils;
4
5
use Psr\Http\Message\StreamInterface;
6
use Psr7Middlewares\Middleware;
7
8
/**
9
 * Trait used to create streams.
10
 */
11
trait StreamTrait
12
{
13
    /**
14
     * Get the stream factory.
15
     *
16
     * @return StreamInterface
17
     */
18
    private static function createStream($file = 'php://temp', $mode = 'r+')
19
    {
20
        $factory = Middleware::getStreamFactory();
21
22
        if ($factory === null) {
23
            if (class_exists('Zend\\Diactoros\\Stream')) {
24
                return new \Zend\Diactoros\Stream($file, $mode);
25
            }
26
27
            throw new \RuntimeException('Unable to create a stream. No stream factory defined');
28
        }
29
30
        return call_user_func($factory, $file, $mode);
31
    }
32
}
33