LongVariableTest   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 274
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 274
rs 10
c 0
b 0
f 0
wmc 23
lcom 1
cbo 3

19 Methods

Rating   Name   Duplication   Size   Complexity  
A testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold() 0 7 1
A testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold() 0 7 1
A testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold() 0 7 1
A testRuleAppliesToFunctionParameterWithNameLongerThanThreshold() 0 7 1
A testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold() 0 7 1
A testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold() 0 13 2
A testRuleAppliesToMethodParameterWithNameLongerThanThreshold() 0 13 2
A testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold() 0 13 2
A testRuleNotAppliesToStaticMembersAccessedInMethod() 0 7 1
A testRuleAppliesToIdenticalVariableOnlyOneTime() 0 7 1
A testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes() 0 13 2
A testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold() 0 7 1
A testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold() 0 7 1
A testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold() 0 7 1
A testRuleAppliesToFieldWithNameLongerThanThreshold() 0 7 1
A testRuleNotAppliesToFieldWithNameEqualToThreshold() 0 7 1
A testRuleNotAppliesToFieldWithNameShorterThanThreshold() 0 7 1
A testRuleAppliesForLongPrivateProperty() 0 7 1
A testRuleAppliesForLongPrivateStaticProperty() 0 7 1
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Rule\Naming;
19
20
use PHPMD\AbstractTest;
21
22
/**
23
 * Test case for the really long variable, parameter and property name rule.
24
 *
25
 * @covers PHPMD\Rule\Naming\LongVariable
26
 */
27
class LongVariableTest extends AbstractTest
28
{
29
    /**
30
     * testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold
31
     *
32
     * @return void
33
     */
34
    public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold()
35
    {
36
        $rule = new LongVariable();
37
        $rule->addProperty('maximum', 17);
38
        $rule->setReport($this->getReportMock(1));
39
        $rule->apply($this->getFunction());
40
    }
41
42
    /**
43
     * testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold
44
     *
45
     * @return void
46
     */
47
    public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold()
48
    {
49
        $rule = new LongVariable();
50
        $rule->addProperty('maximum', 17);
51
        $rule->setReport($this->getReportMock(0));
52
        $rule->apply($this->getFunction());
53
    }
54
55
    /**
56
     * testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold
57
     *
58
     * @return void
59
     */
60
    public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold()
61
    {
62
        $rule = new LongVariable();
63
        $rule->addProperty('maximum', 6);
64
        $rule->setReport($this->getReportMock(0));
65
        $rule->apply($this->getFunction());
66
    }
67
68
    /**
69
     * testRuleAppliesToFunctionParameterWithNameLongerThanThreshold
70
     *
71
     * @return void
72
     */
73
    public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold()
74
    {
75
        $rule = new LongVariable();
76
        $rule->addProperty('maximum', 17);
77
        $rule->setReport($this->getReportMock(1));
78
        $rule->apply($this->getFunction());
79
    }
80
81
    /**
82
     * testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold
83
     *
84
     * @return void
85
     */
86
    public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold()
87
    {
88
        $rule = new LongVariable();
89
        $rule->addProperty('maximum', 17);
90
        $rule->setReport($this->getReportMock(0));
91
        $rule->apply($this->getFunction());
92
    }
93
94
    /**
95
     * testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold
96
     *
97
     * @return void
98
     */
99
    public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold()
100
    {
101
        $rule = new LongVariable();
102
        $rule->addProperty('maximum', 17);
103
        $rule->setReport($this->getReportMock(1));
104
105
        $class = $this->getClass();
106
        $rule->apply($class);
107
108
        foreach ($class->getMethods() as $method) {
109
            $rule->apply($method);
110
        }
111
    }
112
113
    /**
114
     * testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold
115
     *
116
     * @return void
117
     */
118
    public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold()
119
    {
120
        $rule = new LongVariable();
121
        $rule->addProperty('maximum', 6);
122
        $rule->setReport($this->getReportMock(0));
123
        $rule->apply($this->getClass());
124
    }
125
126
    /**
127
     * testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold
128
     *
129
     * @return void
130
     */
131
    public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold()
132
    {
133
        $rule = new LongVariable();
134
        $rule->addProperty('maximum', 17);
135
        $rule->setReport($this->getReportMock(0));
136
        $rule->apply($this->getClass());
137
    }
138
139
    /**
140
     * testRuleAppliesToMethodParameterWithNameLongerThanThreshold
141
     *
142
     * @return void
143
     */
144
    public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold()
145
    {
146
        $rule = new LongVariable();
147
        $rule->addProperty('maximum', 3);
148
        $rule->setReport($this->getReportMock(1));
149
150
        $class = $this->getClass();
151
        $rule->apply($class);
152
153
        foreach ($class->getMethods() as $method) {
154
            $rule->apply($method);
155
        }
156
    }
157
158
    /**
159
     * testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold
160
     *
161
     * @return void
162
     */
163
    public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold()
164
    {
165
        $rule = new LongVariable();
166
        $rule->addProperty('maximum', 17);
167
        $rule->setReport($this->getReportMock(0));
168
        $rule->apply($this->getClass());
169
    }
170
171
    /**
172
     * testRuleAppliesToFieldWithNameLongerThanThreshold
173
     *
174
     * @return void
175
     */
176
    public function testRuleAppliesToFieldWithNameLongerThanThreshold()
177
    {
178
        $rule = new LongVariable();
179
        $rule->addProperty('maximum', 17);
180
        $rule->setReport($this->getReportMock(1));
181
        $rule->apply($this->getClass());
182
    }
183
184
    /**
185
     * testRuleNotAppliesToFieldWithNameEqualToThreshold
186
     *
187
     * @return void
188
     */
189
    public function testRuleNotAppliesToFieldWithNameEqualToThreshold()
190
    {
191
        $rule = new LongVariable();
192
        $rule->addProperty('maximum', 6);
193
        $rule->setReport($this->getReportMock(0));
194
        $rule->apply($this->getClass());
195
    }
196
197
    /**
198
     * testRuleNotAppliesToFieldWithNameShorterThanThreshold
199
     *
200
     * @return void
201
     */
202
    public function testRuleNotAppliesToFieldWithNameShorterThanThreshold()
203
    {
204
        $rule = new LongVariable();
205
        $rule->addProperty('maximum', 8);
206
        $rule->setReport($this->getReportMock(0));
207
        $rule->apply($this->getClass());
208
    }
209
210
    /**
211
     * testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold
212
     *
213
     * @return void
214
     */
215
    public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold()
216
    {
217
        $rule = new LongVariable();
218
        $rule->addProperty('maximum', 3);
219
        $rule->setReport($this->getReportMock(2));
220
221
        $class = $this->getClass();
222
        $rule->apply($class);
223
224
        foreach ($class->getMethods() as $method) {
225
            $rule->apply($method);
226
        }
227
    }
228
229
    /**
230
     * testRuleNotAppliesToStaticMembersAccessedInMethod
231
     *
232
     * @return void
233
     */
234
    public function testRuleNotAppliesToStaticMembersAccessedInMethod()
235
    {
236
        $rule = new LongVariable();
237
        $rule->addProperty('maximum', 3);
238
        $rule->setReport($this->getReportMock(0));
239
        $rule->apply($this->getMethod());
240
    }
241
242
    /**
243
     * testRuleAppliesToIdenticalVariableOnlyOneTime
244
     *
245
     * @return void
246
     */
247
    public function testRuleAppliesToIdenticalVariableOnlyOneTime()
248
    {
249
        $rule = new LongVariable();
250
        $rule->addProperty('maximum', 17);
251
        $rule->setReport($this->getReportMock(2));
252
        $rule->apply($this->getMethod());
253
    }
254
255
    /**
256
     * testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes
257
     *
258
     * @return void
259
     */
260
    public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes()
261
    {
262
        $rule = new LongVariable();
263
        $rule->addProperty('maximum', 17);
264
        $rule->setReport($this->getReportMock(2));
265
266
        $class = $this->getClass();
267
        $rule->apply($class);
268
269
        foreach ($class->getMethods() as $method) {
270
            $rule->apply($method);
271
        }
272
    }
273
    /**
274
     * testRuleAppliesForLongPrivateProperty
275
     *
276
     * @return void
277
     * @since 1.1.0
278
     */
279
    public function testRuleAppliesForLongPrivateProperty()
280
    {
281
        $rule = new LongVariable();
282
        $rule->addProperty('maximum', 17);
283
        $rule->setReport($this->getReportMock(1));
284
        $rule->apply($this->getClass());
285
    }
286
287
    /**
288
     * testRuleAppliesForLongPrivateStaticProperty
289
     *
290
     * @return void
291
     * @since 1.1.0
292
     */
293
    public function testRuleAppliesForLongPrivateStaticProperty()
294
    {
295
        $rule = new LongVariable();
296
        $rule->addProperty('maximum', 17);
297
        $rule->setReport($this->getReportMock(1));
298
        $rule->apply($this->getClass());
299
    }
300
}
301