Mode::isWriteable()   B
last analyzed

Complexity

Conditions 9
Paths 9

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 9
c 1
b 0
f 0
nc 9
nop 0
dl 0
loc 11
rs 8.0555
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Http\Message\Stream\Enum;
15
16
/**
17
 * Enum Mode.
18
 *
19
 * @author Melech Mizrachi
20
 *
21
 * @see    https://www.php.net/manual/en/function.fopen.php
22
 */
23
enum Mode: string
24
{
25
    case READ              = 'r';
26
    case READ_WRITE        = 'r+';
27
    case WRITE             = 'w';
28
    case WRITE_READ        = 'w+';
29
    case WRITE_END         = 'a';
30
    case WRITE_READ_END    = 'a+';
31
    case CREATE_WRITE      = 'x';
32
    case CREATE_WRITE_READ = 'x+';
33
    case WRITE_CREATE      = 'c';
34
    case WRITE_READ_CREATE = 'c+';
35
    case CLOSE_ON_EXEC     = 'e';
36
37
    public function isReadable(): bool
38
    {
39
        return $this === self::READ
40
            || $this === self::READ_WRITE
41
            || $this === self::WRITE_READ
42
            || $this === self::WRITE_READ_END
43
            || $this === self::CREATE_WRITE_READ
44
            || $this === self::WRITE_READ_CREATE;
45
    }
46
47
    public function isWriteable(): bool
48
    {
49
        return $this === self::READ_WRITE
50
            || $this === self::WRITE
51
            || $this === self::WRITE_READ
52
            || $this === self::WRITE_END
53
            || $this === self::WRITE_READ_END
54
            || $this === self::CREATE_WRITE
55
            || $this === self::CREATE_WRITE_READ
56
            || $this === self::WRITE_CREATE
57
            || $this === self::WRITE_READ_CREATE;
58
    }
59
}
60