LocalFile   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
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
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\File;
16
17
use phpDocumentor\Reflection\File;
18
19
/**
20
 * Represents a local file on the file system.
21
 */
22
final class LocalFile implements File
23
{
24
    /**
25
     * Path to the file.
26
     * @var string
27
     */
28
    private $path;
29
30
    /**
31
     * LocalFile constructor.
32
     */
33 4
    public function __construct(string $path)
34
    {
35 4
        if (!file_exists($path)) {
36 1
            throw new \InvalidArgumentException(sprintf('File "%s" does not exist', $path));
37
        }
38
39 3
        $this->path = $path;
40 3
    }
41
42
    /**
43
     * Returns the content of the file as a string.
44
     */
45 1
    public function getContents(): string
46
    {
47 1
        return (string) file_get_contents($this->path);
48
    }
49
50
    /**
51
     * Returns md5 hash of the file.
52
     */
53 1
    public function md5(): string
54
    {
55 1
        return md5_file($this->path);
56
    }
57
58
    /**
59
     * Returns an relative path to the file.
60
     */
61 1
    public function path(): string
62
    {
63 1
        return $this->path;
64
    }
65
}
66