HitCounter::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 35
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 34
nc 1
nop 31
dl 0
loc 70
ccs 35
cts 35
cp 1
crap 1
rs 9.376
c 0
b 0
f 0

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
3
namespace coderius\hitCounter\entities;
4
5
use Yii;
6
use coderius\hitCounter\Module;
7
8
/**
9
 * This is the model class for table "hit_counter".
10
 *
11
 * @property int $id
12
 * @property string $counter_id Counter id generated in widget and passed by query param in inage src
13
 * @property string $cookie_mark
14
 * @property int $js_cookei_enabled
15
 * @property int $js_java_enabled
16
 * @property int $js_timezone_offset
17
 * @property string $js_timezone
18
 * @property string $js_connection
19
 * @property string $js_current_url
20
 * @property string $js_referer_url
21
 * @property int $js_screen_width
22
 * @property int $js_screen_height
23
 * @property int $js_color_depth
24
 * @property string $js_browser_language
25
 * @property int $js_history_length
26
 * @property int $js_is_toutch_device
27
 * @property int $js_processor_ram
28
 * @property string $serv_ip User ip
29
 * @property string $serv_user_agent
30
 * @property string $serv_referer_url
31
 * @property string $serv_server_name
32
 * @property int $serv_auth_user_id User id if exists
33
 * @property string $serv_port
34
 * @property string $serv_cookies
35
 * @property string $serv_os
36
 * @property string $serv_client
37
 * @property string $serv_device
38
 * @property string $serv_brand
39
 * @property string $serv_model
40
 * @property string $serv_bot
41
 * @property string $serv_host_by_ip
42
 * @property int $serv_is_proxy_or_vpn
43
 * @property string $created_at
44
 *
45
 * @property User $servAuthUser
46
 */
47
class HitCounter extends \yii\db\ActiveRecord
48
{
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public static function tableName()
53
    {
54
        return 'hit_counter';
55
    }
56
57
58 9
    public static function create(
59
        $counter_id,
60
        $cookie_mark,
61
        $js_cookei_enabled,
62
        $js_java_enabled,
63
        $js_timezone_offset,
64
        $js_timezone,
65
        $js_connection,
66
        $js_current_url,
67
        $js_referer_url,
68
        $js_screen_width,
69
        $js_screen_height,
70
        $js_color_depth,
71
        $js_browser_language,
72
        $js_history_length,
73
        $js_is_toutch_device,
74
        $js_processor_ram,
75
        $serv_ip,
76
        $serv_user_agent,
77
        $serv_referer_url,
78
        $serv_server_name,
79
        $serv_auth_user_id,
80
        $serv_port,
81
        $serv_cookies,
82
        $serv_os,
83
        $serv_client,
84
        $serv_device,
85
        $serv_brand,
86
        $serv_model,
87
        $serv_bot,
88
        $serv_host_by_ip,
89
        $serv_is_proxy_or_vpn
90
    ): self
91
    {
92 9
        $hit = new static();
93
        
94 9
        $hit->counter_id = $counter_id;
95 9
        $hit->cookie_mark = $cookie_mark;
96 9
        $hit->js_cookei_enabled = $js_cookei_enabled;
97 9
        $hit->js_java_enabled = $js_java_enabled;
98 9
        $hit->js_timezone_offset = $js_timezone_offset;
99 9
        $hit->js_timezone = $js_timezone;
100 9
        $hit->js_connection = $js_connection;
101 9
        $hit->js_current_url = $js_current_url;
102 9
        $hit->js_referer_url = $js_referer_url;
103 9
        $hit->js_screen_width = $js_screen_width;
104 9
        $hit->js_screen_height = $js_screen_height;
105 9
        $hit->js_color_depth = $js_color_depth;
106 9
        $hit->js_browser_language = $js_browser_language;
107 9
        $hit->js_history_length = $js_history_length;
108 9
        $hit->js_is_toutch_device = $js_is_toutch_device;
109 9
        $hit->js_processor_ram = $js_processor_ram;
110 9
        $hit->serv_ip = $serv_ip;
111 9
        $hit->serv_user_agent = $serv_user_agent;
112 9
        $hit->serv_referer_url = $serv_referer_url;
113 9
        $hit->serv_server_name = $serv_server_name;
114 9
        $hit->serv_auth_user_id = $serv_auth_user_id;
115 9
        $hit->serv_port = $serv_port;
116 9
        $hit->serv_cookies = $serv_cookies;
117 9
        $hit->serv_os = $serv_os;
118 9
        $hit->serv_client = $serv_client;
119 9
        $hit->serv_device = $serv_device;
120 9
        $hit->serv_brand = $serv_brand;
121 9
        $hit->serv_model = $serv_model;
122 9
        $hit->serv_bot = $serv_bot;
123 9
        $hit->serv_host_by_ip = $serv_host_by_ip;
124 9
        $hit->serv_is_proxy_or_vpn = $serv_is_proxy_or_vpn;
125 9
        $hit->created_at = gmdate("Y-m-d H:i:s");
126
127 9
        return $hit;
128
    }
129
130
    /**
131
     * @return \yii\db\ActiveQuery
132
     */
133
    public function getServAuthUser()
134
    {
135
        return $this->hasOne(Module::getInstance()->userIdentityClass, ['id' => 'serv_auth_user_id']);
136
    }
137
}
138