CFileContent::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 10
rs 9.4285
1
<?php
2
3
namespace Anax\Content;
4
5
/**
6
 * A read content from filesystem.
7
 *
8
 */
9
class CFileContent
10
{
11
12
    /**
13
     * Properties
14
     *
15
     */
16
    private $path;
17
18
19
20
    /**
21
     * Get file as content.
22
     *
23
     * @param string $file with content
24
     *
25
     * @return string as content of the file
26
     *
27
     * @throws Exception when file does not exist
28
     */
29
    public function get($file) 
30
    {
31
        $target = $this->path . $file;
32
33
        if (!is_readable($target)) {
34
            throw new \Exception("No such content " . $target);
35
        }
36
37
        return file_get_contents($target);
38
    }
39
40
41
42
    /**
43
     * Set base path where  to find content.
44
     *
45
     * @param string $path where content reside
46
     *
47
     * @return $this
48
     */
49 View Code Duplication
    public function setBasePath($path) 
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        if (!is_dir($path)) {
52
            throw new \Exception("Base path for file content is not a directory: " . $path);
53
        }
54
        $this->path = rtrim($path, '/') . '/';
55
56
        return $this;
57
    }
58
}
59