Completed
Push — develop ( 373768...b82813 )
by Mike
05:50
created

FlySystemFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getContents() 0 4 1
A md5() 0 4 1
A path() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Parser;
17
18
use League\Flysystem\FileNotFoundException;
19
use League\Flysystem\FilesystemInterface;
20
use phpDocumentor\Reflection\File;
21
22
final class FlySystemFile implements File
23
{
24
    /** @var FilesystemInterface */
25
    private $fileSystem;
26
27
    /** @var string */
28
    private $fileName;
29
30 3
    public function __construct(FilesystemInterface $fileSystem, string $fileName)
31
    {
32 3
        $this->fileSystem = $fileSystem;
33 3
        $this->fileName = $fileName;
34 3
    }
35
36
    /**
37
     * Returns the content of the file as a string.
38
     *
39
     * @throws FileNotFoundException
40
     */
41 1
    public function getContents(): string
42
    {
43 1
        return $this->fileSystem->read($this->fileName);
44
    }
45
46
    /**
47
     * Returns md5 hash of the file.
48
     *
49
     * @throws FileNotFoundException
50
     */
51 1
    public function md5(): string
52
    {
53 1
        return md5($this->getContents());
54
    }
55
56
    /**
57
     * Returns an relative path to the file.
58
     */
59 1
    public function path(): string
60
    {
61 1
        return $this->fileName;
62
    }
63
}
64