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

ReadableDocument::getExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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