fopen()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.125

Importance

Changes 0
Metric Value
cc 3
eloc 9
c 0
b 0
f 0
nc 4
nop 4
dl 0
loc 16
ccs 2
cts 4
cp 0.5
crap 4.125
rs 9.9666
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage;
18
19
use RuntimeException;
20
21
/**
22
 * The original php function has mixed return values, either a resource or
23
 * boolean false. But we want an exception.
24
 *
25
 * @param string $filename
26
 * @param string $mode
27 9
 * @param bool $useIncludePath
28
 * @param mixed $context
29
 * @return resource
30 9
 */
31
function fopen(string $filename, string $mode, bool $useIncludePath = true, $context = null)
32
{
33 9
    if (is_resource($context)) {
34
        $result = \fopen($filename, $mode, $useIncludePath, $context);
35
    } else {
36
        $result = \fopen($filename, $mode, $useIncludePath);
37
    }
38
39
    if ($result === false) {
40 9
        throw new RuntimeException(sprintf(
41
            'Failed to open resource `%s`',
42
            $filename
43
        ));
44
    }
45
46
    return $result;
47
}
48