Comments::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 54
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 31
c 1
b 1
f 0
nc 4
nop 16
dl 0
loc 54
rs 9.424

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace AL\Common\Model\Comments;
3
4
use AL\Common\DAO\CommentsDAO;
5
6
require_once __DIR__."/../../../config/config.php";
7
8
/**
9
 * Maps to the temporary `temp` comments table
10
 */
11
class Comments {
12
    private $comments_id;
13
    private $timestamp;
14
    private $post_date;
15
    private $user_id;
16
    private $user_comment_count;
17
    private $user_subm_count;
18
    private $userid;
19
    private $email;
20
    private $join_date;
21
    private $karma;
22
    private $show_email;
23
    private $avatar_image;
24
    private $game_id;
25
    private $game_name;
26
    private $comment_type;
27
    private $comment;
28
    private $review_id;
29
30
    public function __construct(
31
        $comments_id,
32
        $timestamp,
33
        $user_id,
34
        $user_comment_count,
35
        $user_subm_count,
36
        $userid,
37
        $email,
38
        $join_date,
39
        $karma,
40
        $show_email,
41
        $avatar_ext,
42
        $game_id,
43
        $game_name,
44
        $comment_type,
45
        $comment,
46
        $review_id
47
    ) {
48
        $this->comments_id = $comments_id;
49
        $this->timestamp = $timestamp;
50
        $this->post_date = $timestamp;
51
        $this->user_id = $user_id;
52
        $this->user_comment_count = $user_comment_count;
53
        $this->user_subm_count = $user_subm_count;
54
        $this->userid = $userid;
55
        $this->email = $email;
56
        $this->join_date = $join_date;
57
        $this->karma = $karma;
58
        $this->show_email = $show_email;
59
        $this->game_id = $game_id;
60
        $this->game_name = $game_name;
61
        $this->comment_type = $comment_type;
62
        $this->comment = $comment;
63
        $this->review_id = $review_id;
64
65
        if ($avatar_ext && $avatar_ext !== "") {
66
            $this->avatar_image = $GLOBALS['user_avatar_path']."/{$user_id}.{$avatar_ext}";
67
        } else {
68
            $this->avatar_image = $GLOBALS['style_folder']."/images/default_avatar_image.png";
69
        }
70
71
        $oldcomment = $comment;
72
        $oldcomment = nl2br($oldcomment);
73
        $oldcomment = InsertALCode($oldcomment);
74
        $oldcomment = trim($oldcomment);
75
        $oldcomment = RemoveSmillies($oldcomment);
76
        $this->comment = stripslashes($oldcomment);
77
78
        if ($join_date == "") {
79
            $this->join_date = "unknown";
80
        } else {
81
            $this->join_date = date("d-m-y", $join_date);
82
        }
83
        $this->post_date = date("F j, Y", $timestamp);
84
    }
85
86
    public function getCommentsId() {
87
        return $this->comments_id;
88
    }
89
90
    public function getTimestamp() {
91
        return $this->timestamp;
92
    }
93
94
    public function getUserId() {
95
        return $this->user_id;
96
    }
97
98
    public function getUser() {
99
        return $this->userid;
100
    }
101
102
    public function getEmail() {
103
        return $this->email;
104
    }
105
106
    public function getJoinDate() {
107
        return $this->join_date;
108
    }
109
110
    public function getKarma() {
111
        return $this->karma;
112
    }
113
114
    public function getShowEmail() {
115
        return $this->show_email;
116
    }
117
118
    public function getPostDate() {
119
        return $this->post_date;
120
    }
121
122
    public function getAvatarImage() {
123
        return $this->avatar_image;
124
    }
125
126
    public function getGameId() {
127
        return $this->game_id;
128
    }
129
130
    public function getReviewId() {
131
        return $this->review_id;
132
    }
133
134
    public function getGameName() {
135
        return $this->game_name;
136
    }
137
138
    public function getCommentType() {
139
        return $this->comment_type;
140
    }
141
142
    public function getComments() {
143
        return $this->comment;
144
    }
145
146
    public function getUserCommentCount() {
147
        return $this->user_comment_count;
148
    }
149
150
    public function getUserSubCount() {
151
        return $this->user_subm_count;
152
    }
153
}
154