StreamInput   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 6 2
A readLine() 0 6 2
A readAll() 0 6 2
A openStream() 0 4 1
1
<?php
2
/*
3
 * PHP SAPI Library
4
 * Copyright (C) 2020 Christian Neff
5
 *
6
 * Permission to use, copy, modify, and/or distribute this software for
7
 * any purpose with or without fee is hereby granted, provided that the
8
 * above copyright notice and this permission notice appear in all copies.
9
 */
10
11
namespace Secondtruth\SAPI\Input;
12
13
use Secondtruth\SAPI\InputInterface;
14
use Secondtruth\SAPI\Stream\AbstractStream;
15
16
/**
17
 * The StreamInput class.
18
 *
19
 * @author Christian Neff <[email protected]>
20
 */
21
class StreamInput extends AbstractStream implements InputInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function read(int $length): ?string
27
    {
28
        $chunk = fread($this->stream, $length);
29
30
        return $chunk !== false ? $chunk : null;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function readLine(?int $length = null): ?string
37
    {
38
        $chunk = fgets($this->stream, $length);
39
40
        return $chunk !== false ? $chunk : null;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function readAll(): ?string
47
    {
48
        $contents = stream_get_contents($this->stream);
49
50
        return $contents !== false ? $contents : null;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    protected function openStream(string $stream)
57
    {
58
        return fopen($stream, 'r');
59
    }
60
}
61