Passed
Push — develop ( 7d8d36...594335 )
by Florian
07:23 queued 10s
created

fopen()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.7085

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 4
dl 0
loc 16
ccs 4
cts 7
cp 0.5714
crap 3.7085
rs 9.9666
c 0
b 0
f 0
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
function fopen(string $filename, string $mode, bool $useIncludePath = true, $context = null)
26
{
27 9
    if (is_resource($context)) {
28
        $result = \fopen($filename, $mode, $useIncludePath, $context);
29
    } else {
30 9
        $result = \fopen($filename, $mode, $useIncludePath);
31
    }
32
33 9
    if ($result === false) {
34
        throw new RuntimeException(sprintf(
35
            'Failed to open file `%s` with fopen()',
36
            $filename
37
        ));
38
    }
39
40 9
    return $result;
41
}
42