Completed
Pull Request — master (#48)
by Vladimir
09:52
created

ReadableDocument   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A getRelativeFilePath() 0 4 1
A getExtension() 0 4 1
A getBaseName() 0 4 1
A getFilePath() 0 4 1
A getFileName() 0 4 1
refreshFileContent() 0 1 ?
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Document;
9
10
use allejo\stakx\System\Filesystem;
11
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
12
13
abstract class ReadableDocument
14
{
15
    protected $filePath;
16
    protected $fs;
17
18
    public function __construct($filePath)
19
    {
20
        $this->fs = new Filesystem();
21
        $p = $this->filePath = $this->fs->absolutePath($filePath);
22
23
        if (!$this->fs->exists($p))
24
        {
25
            throw new FileNotFoundException("The following file could not be found: ${p}");
26
        }
27
28
        $this->extension = strtolower($this->fs->getExtension($p));
29
30
        $this->refreshFileContent();
31
    }
32
33
    final public function getRelativeFilePath()
34
    {
35
        return $this->fs->getRelativePath($this->filePath);
36
    }
37
38
    final public function getExtension()
39
    {
40
        return $this->extension;
41
    }
42
43
    final public function getBaseName()
44
    {
45
        return $this->fs->getBaseName($this->filePath);
46
    }
47
48
    final public function getFilePath()
49
    {
50
        return $this->filePath;
51
    }
52
53
    final public function getFileName()
54
    {
55
        return $this->fs->getFileName($this->filePath);
56
    }
57
58
    abstract public function refreshFileContent();
59
}
60