Completed
Push — feature/0.7.0 ( 38440f...02d6a4 )
by Ryuichi
07:28
created

LoggerProvider   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 257
Duplicated Lines 60.7 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 156
loc 257
rs 10
c 0
b 0
f 0
wmc 23
lcom 0
cbo 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A loggerAdapterProvider() 0 15 1
A loggerAdapterWithPlaceholderProvider() 0 9 1
A logLevelDebugProvider() 15 15 1
A logLevelInfoProvider() 15 15 1
A logLevelNoticeProvider() 15 15 1
A logLevelWarnProvider() 15 15 1
A logLevelWarningProvider() 15 15 1
A logLevelErrorProvider() 15 15 1
A logLevelCriticalProvider() 15 15 1
A logLevelAlertProvider() 15 15 1
A logLevelEmergencyProvider() 15 15 1
A logLevelFatalProvider() 15 15 1
A loggerFormatterProvider() 0 11 1
A loggerFormatterDateTimeProvider() 0 9 1
A writeTimingProvider() 0 7 1
A unRotateByCycleProvider() 3 17 4
A rotateByCycleProvider() 3 20 4

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
namespace WebStream\Log\Test\Providers;
3
4
/**
5
 * LoggerProvider
6
 * @author Ryuichi TANAKA.
7
 * @since 2016/01/30
8
 * @version 0.7
9
 */
10
trait LoggerProvider
11
{
12
    public function loggerAdapterProvider()
13
    {
14
        return [
15
            ["debug"],
16
            ["info"],
17
            ["notice"],
18
            ["warn"],
19
            ["warning"],
20
            ["error"],
21
            ["critical"],
22
            ["alert"],
23
            ["emergency"],
24
            ["fatal"]
25
        ];
26
    }
27
28
    public function loggerAdapterWithPlaceholderProvider()
29
    {
30
        return [
31
            ["debug", "log message for debug.", "log message for { level }.", ["level" => "debug"]],
32
            ["debug", "log message for debug.", "log message for {level }.", ["level" => "debug"]],
33
            ["debug", "log message for debug.", "log message for { level}.", ["level" => "debug"]],
34
            ["debug", "log message for debug.", "log message for {level}.", ["level" => "debug"]]
35
        ];
36
    }
37
38 View Code Duplication
    public function logLevelDebugProvider()
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...
39
    {
40
        return [
41
            ["debug", true],
42
            ["info", true],
43
            ["notice", true],
44
            ["warn", true],
45
            ["warning", true],
46
            ["error", true],
47
            ["critical", true],
48
            ["alert", true],
49
            ["emergency", true],
50
            ["fatal", true]
51
        ];
52
    }
53
54 View Code Duplication
    public function logLevelInfoProvider()
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...
55
    {
56
        return [
57
            ["debug", false],
58
            ["info", true],
59
            ["notice", true],
60
            ["warn", true],
61
            ["warning", true],
62
            ["error", true],
63
            ["critical", true],
64
            ["alert", true],
65
            ["emergency", true],
66
            ["fatal", true]
67
        ];
68
    }
69
70 View Code Duplication
    public function logLevelNoticeProvider()
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...
71
    {
72
        return [
73
            ["debug", false],
74
            ["info", false],
75
            ["notice", true],
76
            ["warn", true],
77
            ["warning", true],
78
            ["error", true],
79
            ["critical", true],
80
            ["alert", true],
81
            ["emergency", true],
82
            ["fatal", true]
83
        ];
84
    }
85
86 View Code Duplication
    public function logLevelWarnProvider()
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...
87
    {
88
        return [
89
            ["debug", false],
90
            ["info", false],
91
            ["notice", false],
92
            ["warn", true],
93
            ["warning", true],
94
            ["error", true],
95
            ["critical", true],
96
            ["alert", true],
97
            ["emergency", true],
98
            ["fatal", true]
99
        ];
100
    }
101
102 View Code Duplication
    public function logLevelWarningProvider()
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...
103
    {
104
        return [
105
            ["debug", false],
106
            ["info", false],
107
            ["notice", false],
108
            ["warn", true],
109
            ["warning", true],
110
            ["error", true],
111
            ["critical", true],
112
            ["alert", true],
113
            ["emergency", true],
114
            ["fatal", true]
115
        ];
116
    }
117
118 View Code Duplication
    public function logLevelErrorProvider()
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...
119
    {
120
        return [
121
            ["debug", false],
122
            ["info", false],
123
            ["notice", false],
124
            ["warn", false],
125
            ["warning", false],
126
            ["error", true],
127
            ["critical", true],
128
            ["alert", true],
129
            ["emergency", true],
130
            ["fatal", true]
131
        ];
132
    }
133
134 View Code Duplication
    public function logLevelCriticalProvider()
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...
135
    {
136
        return [
137
            ["debug", false],
138
            ["info", false],
139
            ["notice", false],
140
            ["warn", false],
141
            ["warning", false],
142
            ["error", false],
143
            ["critical", true],
144
            ["alert", true],
145
            ["emergency", true],
146
            ["fatal", true]
147
        ];
148
    }
149
150 View Code Duplication
    public function logLevelAlertProvider()
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...
151
    {
152
        return [
153
            ["debug", false],
154
            ["info", false],
155
            ["notice", false],
156
            ["warn", false],
157
            ["warning", false],
158
            ["error", false],
159
            ["critical", false],
160
            ["alert", true],
161
            ["emergency", true],
162
            ["fatal", true]
163
        ];
164
    }
165
166 View Code Duplication
    public function logLevelEmergencyProvider()
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...
167
    {
168
        return [
169
            ["debug", false],
170
            ["info", false],
171
            ["notice", false],
172
            ["warn", false],
173
            ["warning", false],
174
            ["error", false],
175
            ["critical", false],
176
            ["alert", false],
177
            ["emergency", true],
178
            ["fatal", true]
179
        ];
180
    }
181
182 View Code Duplication
    public function logLevelFatalProvider()
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...
183
    {
184
        return [
185
            ["debug", false],
186
            ["info", false],
187
            ["notice", false],
188
            ["warn", false],
189
            ["warning", false],
190
            ["error", false],
191
            ["critical", false],
192
            ["alert", false],
193
            ["emergency", false],
194
            ["fatal", true]
195
        ];
196
    }
197
198
    public function loggerFormatterProvider()
199
    {
200
        return [
201
            ["log.test3_1.ini", "message", "message"],
202
            ["log.test3_2.ini", "message", "[debug] message"],
203
            ["log.test3_3.ini", "message", "[DEBUG] message"],
204
            ["log.test3_4.ini", "message", "[debug     ] message"],
205
            ["log.test3_5.ini", "message", "[DEBUG     ] message"],
206
            ["log.test3_6.ini", "message", "[webstream.logtest] message"]
207
        ];
208
    }
209
210
    public function loggerFormatterDateTimeProvider()
211
    {
212
        return [
213
            ["log.test4_1.ini", "/(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/", "message", "message"],
214
            ["log.test4_2.ini", "/(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})/", "message", "message"],
215
            ["log.test4_3.ini", "/(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/", "message", "           message"],
216
            ["log.test4_4.ini", "/(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})/", "message", "       message"]
217
        ];
218
    }
219
220
    public function writeTimingProvider()
221
    {
222
        return [
223
            [true, "b", "a", "a", "a".PHP_EOL."b".PHP_EOL."a".PHP_EOL],
224
            [false,"b", "a", "a", "b".PHP_EOL."a".PHP_EOL."a".PHP_EOL]
225
        ];
226
    }
227
228
    public function unRotateByCycleProvider()
229
    {
230
        $day_of_year = 24 * 365;
231
        $year = date("Y");
232 View Code Duplication
        if (($year % 4 === 0 && $year % 100 !== 0) || $year % 400 === 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
233
            $day_of_year = 24 * 366;
234
        }
235
236
        return [
237
            ["log.test6.day.ini", 1],
238
            ["log.test6.day.ini", 23],
239
            ["log.test6.week.ini", 24],
240
            ["log.test6.week.ini", 24 * 7 - 1],
241
            ["log.test6.month.ini", 24 * intval(date("t", time())) - 1],
242
            ["log.test6.year.ini", $day_of_year - 1]
243
        ];
244
    }
245
246
    public function rotateByCycleProvider()
247
    {
248
        $day_of_month = intval(date("t", time()));
249
        $day_of_year = 24 * 365;
250
        $year = date("Y");
251 View Code Duplication
        if (($year % 4 === 0 && $year % 100 !== 0) || $year % 400 === 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
252
            $day_of_year = 24 * 366;
253
        }
254
255
        return [
256
            ["log.test6.day.ini", 24],
257
            ["log.test6.day.ini", 25],
258
            ["log.test6.week.ini", 24 * 7],
259
            ["log.test6.week.ini", 24 * 7 + 1],
260
            ["log.test6.month.ini", 24 * $day_of_month],
261
            ["log.test6.month.ini", 24 * $day_of_month + 1],
262
            ["log.test6.year.ini", $day_of_year],
263
            ["log.test6.year.ini", $day_of_year + 1]
264
        ];
265
    }
266
}
267