StreamTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createStream() 0 20 4
1
<?php
2
3
namespace Psr7Middlewares\Utils;
4
5
use Psr7Middlewares\Middleware;
6
use Psr\Http\Message\StreamInterface;
7
8
/**
9
 * Trait used to create streams.
10
 */
11
trait StreamTrait
12
{
13
    /**
14
     * Get the stream factory.
15
     *
16
     * @param string|StreamInterface $file Filename or stream it's replacing
17
     * @param string                 $mode
18
     *
19
     * @return StreamInterface
20
     */
21
    private static function createStream($file = 'php://temp', $mode = 'r+')
22
    {
23
        $factory = Middleware::getStreamFactory();
24
        $replacing = null;
25
26
        if ($file instanceof StreamInterface) {
27
            $replacing = $file;
28
            $file = 'php://temp';
29
        }
30
31
        if ($factory === null) {
32
            if (class_exists('Zend\\Diactoros\\Stream')) {
33
                return new \Zend\Diactoros\Stream($file, $mode);
34
            }
35
36
            throw new \RuntimeException('Unable to create a stream. No stream factory defined');
37
        }
38
39
        return call_user_func($factory, $file, $mode, $replacing);
40
    }
41
}
42