Completed
Pull Request — master (#48)
by Vladimir
02:36
created

ReadableDocument::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
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
0 ignored issues
show
Coding Style introduced by
ReadableDocument does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
14
{
15
    protected $filePath;
16
    protected $fs;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
17
18 116
    public function __construct($filePath)
19
    {
20 116
        $this->fs = new Filesystem();
21 116
        $p = $this->filePath = $this->fs->absolutePath((string)$filePath);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
22
23 116
        if (!$this->fs->exists($p))
24
        {
25 1
            throw new FileNotFoundException("The following file could not be found: ${p}");
26
        }
27
28
        $this->extension = strtolower($this->fs->getExtension($p));
0 ignored issues
show
Bug introduced by
The property extension does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
30
        $this->refreshFileContent();
31
    }
32
33
    final public function getRelativeFilePath()
34
    {
35 65
        return $this->fs->getRelativePath($this->filePath);
36
    }
37
38
    final public function getExtension()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
39
    {
40 7
        return $this->extension;
41
    }
42
43
    final public function getBaseName()
44
    {
45 62
        return $this->fs->getBaseName($this->filePath);
46
    }
47
48
    final public function getFilePath()
49
    {
50 19
        return $this->filePath;
51
    }
52
53
    final public function getFileName()
54
    {
55 30
        return $this->fs->getFileName($this->filePath);
56
    }
57
58
    abstract public function refreshFileContent();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
59
}
60