CFileContent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 18 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 50
rs 10
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A setBasePath() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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