Test Failed
Branch main (8f4107)
by Bingo
08:27 queued 02:15
created

IoUtil   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFile() 0 6 2
A closeSilently() 0 5 2
A readInputStream() 0 8 2
1
<?php
2
3
namespace Jabe\Engine\Impl\Util;
4
5
use Jabe\Engine\ProcessEngineException;
6
use Jabe\Engine\Impl\ProcessEngineLogger;
7
8
class IoUtil
9
{
10
    //private static final EngineUtilLogger LOG = ProcessEngineLogger.UTIL_LOGGER;
11
    public static function readInputStream($inputStream, string $inputStreamName): string
12
    {
13
        try {
14
            $meta = stream_get_meta_data($inputStream);
15
            return fread($inputStream, filesize($meta['uri']));
16
        } catch (\Exception $e) {
17
            //throw LOG.exceptionWhileReadingStream(inputStreamName, e);
18
            throw new \Exception(sprintf("exceptionWhileReadingStream %s", $inputStreamName));
19
        }
20
    }
21
22
    public static function getFile(string $filePath)
23
    {
24
        if (file_exists($filePath)) {
25
            return fopen($filePath, 'r+');
26
        } else {
27
            throw new \Exception(sprintf("exceptionWhileGettingFilee %s", $filePath));
28
        }
29
    }
30
31
    public static function closeSilently($file): void
32
    {
33
        try {
34
            fclose($file);
35
        } catch (\Exception $e) {
36
            // ignored
37
        }
38
    }
39
}
40