Passed
Push — master ( 9251f2...ca8fc4 )
by Herberto
03:14
created

FileSystemAdapter::readFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Hgraca\Phorensic\SharedKernel\Port\FileSystem\Adapter\FileSystem;
4
5
use Hgraca\FileSystem\Exception\FileNotFoundException as FileSystemFileNotFoundException;
6
use Hgraca\FileSystem\Exception\InvalidPathException as FileSystemInvalidPathException;
7
use Hgraca\FileSystem\FileSystemInterface as FileSystemFileSystemInterface;
8
use Hgraca\FileSystem\LocalFileSystem;
9
use Hgraca\Phorensic\SharedKernel\Port\FileSystem\Exception\FileNotFoundException;
10
use Hgraca\Phorensic\SharedKernel\Port\FileSystem\Exception\InvalidPathException;
11
use Hgraca\Phorensic\SharedKernel\Port\FileSystem\FileSystemInterface;
12
13
final class FileSystemAdapter implements FileSystemInterface
14
{
15
    /**
16
     * @var FileSystemFileSystemInterface
17
     */
18
    private $fileSystem;
19
20
    public function __construct(FileSystemFileSystemInterface $fileSystem = null)
21
    {
22
        $this->fileSystem = $fileSystem ?? new LocalFileSystem(LocalFileSystem::IDEMPOTENT);
23
    }
24
25
    /**
26
     * @throws FileNotFoundException
27
     * @throws InvalidPathException
28
     */
29
    public function readFile(string $path): string
30
    {
31
        try {
32
            return $this->fileSystem->readFile($path);
33
        } catch (FileSystemInvalidPathException $e) {
34
            throw new InvalidPathException('', 0, $e);
35
        } catch (FileSystemFileNotFoundException $e) {
36
            throw new FileNotFoundException('', 0, $e);
37
        }
38
    }
39
40
    public function getExtension(string $path): string
41
    {
42
        return $this->fileSystem->getExtension($path);
43
    }
44
}
45