User::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 2
nop 8
dl 0
loc 24
rs 9.9
c 0
b 0
f 0

How to fix   Many Parameters   

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\User;
3
4
require_once __DIR__."/../../../config/config.php";
5
require_once __DIR__."/../../../lib/functions.php";
6
7
/**
8
 * Maps to the `user` table
9
 */
10
class User {
11
    private $id;
12
    private $name;
13
    private $email;
14
    private $join_date;
15
    private $karma;
16
    private $show_email;
17
    private $avatar;
18
    private $news_count;
19
20
    public function __construct(
21
        $id,
22
        $name,
23
        $email,
24
        $join_date,
25
        $karma,
26
        $show_email,
27
        $avatar_ext,
28
        $news_count = 0
29
    ) {
30
        $this->id = $id;
31
        $this->name = $name;
32
        $this->email = $email;
33
        $this->join_date = $join_date;
34
        $this->karma = $karma;
35
        $this->show_email = $show_email;
36
37
        if ($avatar_ext != null && $avatar_ext != '') {
38
            $this->avatar = $GLOBALS['user_avatar_path'].$id.'.'.$avatar_ext;
39
        } else {
40
            $this->avatar = "/themes/styles/1/images/default_avatar_image.png";
41
        }
42
43
        $this->news_count = $news_count;
44
    }
45
46
    public function getId() {
47
        return $this->id;
48
    }
49
50
    public function getName() {
51
        return $this->name;
52
    }
53
54
    public function getEmail() {
55
        return $this->email;
56
    }
57
58
    public function getJoinDate() {
59
        return $this->join_date;
60
    }
61
62
    public function getKarma() {
63
        return $this->karma;
64
    }
65
66
    public function getShowEmail() {
67
        return $this->show_email;
68
    }
69
70
    public function getAvatar() {
71
        return $this->avatar;
72
    }
73
74
    public function getNewsCount() {
75
        return $this->news_count;
76
    }
77
}
78