FileSystemAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 32
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A readFile() 0 10 3
A getExtension() 0 4 1
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