Comment   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 35.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 19
loc 54
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A gravatar() 0 4 1
A getAll() 11 11 1
A get() 8 8 1
A user() 0 6 1

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 Almrooth\Comment;
4
5
use \Anax\Database\ActiveRecordModel;
6
7
use \Almrooth\Comment\User;
8
9
/**
10
 * A database driven model.
11
 * @SuppressWarnings("camelcase")
12
 */
13
class Comment extends ActiveRecordModel
14
{
15
    /**
16
     * @var string $tableName name of the database table.
17
     */
18
    protected $tableName = "rv1_comments";
19
20
21
    /**
22
     * Columns in the table.
23
     *
24
     * @var integer $id primary key auto incremented.
25
     */
26
    public $id;
27
    public $user_id;
28
    public $content;
29
    public $created;
30
    public $updated;
31
    public $deleted;
32
33
34 3
    public function gravatar($email)
35
    {
36 3
        return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($email)));
37
    }
38
39 1 View Code Duplication
    public function getAll()
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...
40
    {
41 1
        $comments = $this->findAll();
42
43 1
        return array_map(function ($comment) {
44 1
            $user = $this->user($comment->user_id);
45 1
            $comment->gravatar = $this->gravatar($user->email);
46 1
            $comment->username = $user->username;
47 1
            return $comment;
48 1
        }, $comments);
49
    }
50
51 1 View Code Duplication
    public function get($id)
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...
52
    {
53 1
        $comment = $this->find("id", $id);
54 1
        $user = $this->user($comment->user_id);
55 1
        $comment->gravatar = $this->gravatar($user->email);
56 1
        $comment->username = $user->username;
57 1
        return $comment;
58
    }
59
60 3
    public function user($id)
61
    {
62 3
        $user = new User();
63 3
        $user->setDb($this->db);
64 3
        return $user->find("id", $id);
65
    }
66
}
67