File   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFileContents() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Utilities;
6
7
use SimpleSAML\SAML2\Exception\RuntimeException;
8
9
use function file_get_contents;
10
use function is_readable;
11
use function sprintf;
12
13
/**
14
 * Various File Utilities
15
 */
16
class File
17
{
18
    /**
19
     * @param string $file full absolute path to the file
20
     */
21
    public static function getFileContents(string $file): string
22
    {
23
        if (!is_readable($file)) {
24
            throw new RuntimeException(sprintf(
25
                'File "%s" does not exist or is not readable',
26
                $file,
27
            ));
28
        }
29
30
        $contents = file_get_contents($file);
31
        if ($contents === false) {
32
            throw new RuntimeException(sprintf(
33
                'Could not read from existing and readable file "%s"',
34
                $file,
35
            ));
36
        }
37
38
        return $contents;
39
    }
40
}
41