Passed
Push — master ( bf6fa9...817f88 )
by Nikolaos
06:58
created

StreamTrait::checkReadable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 1
b 0
f 0
ccs 0
cts 5
cp 0
crap 6
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * (c) Phalcon Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Phalcon\Http\Message\Traits;
15
16
use RuntimeException;
17
18
/**
19
 * Trait StreamTrait
20
 */
21
trait StreamTrait
22
{
23
    /**
24
     * @return bool
25
     */
26
    abstract public function isReadable(): bool;
27
28
    /**
29
     * @return bool
30
     */
31
    abstract public function isSeekable(): bool;
32
33
    /**
34
     * @return bool
35
     */
36
    abstract public function isWritable(): bool;
37
38
    /**
39
     * Checks if a handle is available and throws an exception otherwise
40
     */
41
    private function checkHandle(): void
42
    {
43
        if (null === $this->handle) {
44
            throw new RuntimeException(
45
                'A valid resource is required.'
46
            );
47
        }
48
    }
49
50
    /**
51
     * Checks if a handle is readable and throws an exception otherwise
52
     */
53
    private function checkReadable(): void
54
    {
55
        if (true !== $this->isReadable()) {
56
            throw new RuntimeException(
57
                'The resource is not readable.'
58
            );
59
        }
60
    }
61
62
    /**
63
     * Checks if a handle is seekable and throws an exception otherwise
64
     */
65
    private function checkSeekable(): void
66
    {
67
        if (true !== $this->isSeekable()) {
68
            throw new RuntimeException(
69
                'The resource is not seekable.'
70
            );
71
        }
72
    }
73
74
    /**
75
     * Checks if a handle is writeable and throws an exception otherwise
76
     */
77
    private function checkWritable(): void
78
    {
79
        if (true !== $this->isWritable()) {
80
            throw new RuntimeException(
81
                'The resource is not writable.'
82
            );
83
        }
84
    }
85
}
86