GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DropCapsTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 241
Duplicated Lines 38.17 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 1
dl 92
loc 241
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A tearDown() 0 3 1
A testHeadings() 0 39 1
A testNoHeading() 0 29 1
A testAlreadyHasMarkup() 0 26 1
A testStartsWithHTMLEntity() 0 17 1
A testStartsWithHTMLTag() 23 23 1
A testWordMode() 23 23 1
A testWordModeStartWithEntity() 23 23 1
A testProcessManualMarkup() 0 19 1
A testMarkdownStyle() 23 23 1

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
/*
3
 * This file is part of the trefoil application.
4
 *
5
 * (c) Miguel Angel Gabriel <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Trefoil\Tests\Helpers;
11
12
use Trefoil\Helpers\DropCaps;
13
14
class DropCapsTest extends \PHPUnit_Framework_TestCase
15
{
16
    public function setUp()
17
    {
18
    }
19
20
    public function tearDown()
21
    {
22
    }
23
24
    public function testHeadings()
25
    {
26
        $input = array(
27
            '<h1>H1 heading</h1>',
28
            '<p>First paragraph under H1</p>',
29
            '<h2>H2 heading</h2>',
30
            '<p>Other first paragraph under H2</p>',
31
            '<h3>H3 heading</h3>',
32
            '<p>Another First paragraph under H3</p>'
33
        );
34
35
        $expected = array(
36
            '<h1>H1 heading</h1>',
37
            '<p class="has-dropcaps"><span class="dropcaps">F</span>irst paragraph under H1</p>',
38
            '<h2>H2 heading</h2>',
39
            '<p>Other first paragraph under H2</p>',
40
            '<h3>H3 heading</h3>',
41
            '<p class="has-dropcaps"><span class="dropcaps">A</span>nother First paragraph under H3</p>'
42
        );
43
44
45
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_LETTER, 1);
46
47
        // must not change
48
        $dropCaps->createForFirstParagraph();
49
        $this->assertEquals(
50
             implode("", $input),
51
             $dropCaps->getOutput(),
52
             'Do not change first paragraph in text if preceding '
53
        );
54
55
        // must change
56
        $dropCaps->createForHeadings(array(1, 3));
57
        $this->assertEquals(
58
             implode("", $expected),
59
             $dropCaps->getOutput(),
60
             'Change only selected levels'
61
        );
62
    }
63
64
    public function testNoHeading()
65
    {
66
        $input = array(
67
            '<p>First paragraph</p>',
68
            '<p>Second paragraph</p>',
69
            '<h2>H2 heading</h2>',
70
            '<p>Other first paragraph under H2</p>',
71
            '<h3>H3 heading</h3>',
72
            '<p>Another First paragraph under H3</p>'
73
        );
74
75
        $expected = array(
76
            '<p class="has-dropcaps"><span class="dropcaps">F</span>irst paragraph</p>',
77
            '<p>Second paragraph</p>',
78
            '<h2>H2 heading</h2>',
79
            '<p>Other first paragraph under H2</p>',
80
            '<h3>H3 heading</h3>',
81
            '<p>Another First paragraph under H3</p>'
82
        );
83
84
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_LETTER, 1);
85
86
        $dropCaps->createForFirstParagraph();
87
        $this->assertEquals(
88
             implode("", $expected),
89
             $dropCaps->getOutput(),
90
             'Change only first paragraph without heading'
91
        );
92
    }
93
94
    public function testAlreadyHasMarkup()
95
    {
96
        $input = array(
97
            '<p class="has-dropcaps"><span class="dropcaps">- F</span>irst paragraph</p>',
98
            '<h2>H2 heading</h2>',
99
            '<p class="has-dropcaps"><span class="dropcaps">* O</span>Other first paragraph under H2</p>',
100
        );
101
102
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_LETTER, 1);
103
104
        // must not change
105
        $dropCaps->createForFirstParagraph();
106
        $this->assertEquals(
107
             implode("", $input),
108
             $dropCaps->getOutput(),
109
             'Do not change first paragraph in text if already has dropcaps markup'
110
        );
111
112
        // must not change
113
        $dropCaps->createForHeadings(array(1, 2));
114
        $this->assertEquals(
115
             implode("", $input),
116
             $dropCaps->getOutput(),
117
             'Do not change first paragraph under headings if already has dropcaps markup'
118
        );
119
    }
120
121
    public function testStartsWithHTMLEntity()
122
    {
123
        $input = array(
124
            '&nbsp;First paragraph </p>',
125
            '<h2>H2 heading</h2>',
126
            '<p>Other first paragraph under H2</p>',
127
        );
128
129
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_LETTER, 1);
130
131
        // must not change
132
        $dropCaps->createForFirstParagraph();
133
        $this->assertEquals(
134
             implode("", $input),
135
             $dropCaps->getOutput()
136
        );
137
    }
138
139 View Code Duplication
    public function testStartsWithHTMLTag()
140
    {
141
        $input = array(
142
            '<p><em>First</em> paragraph </p>',
143
            '<h2>H2 heading</h2>',
144
            '<p>Other first paragraph under H2</p>',
145
        );
146
147
        $expected = array(
148
            '<p class="has-dropcaps"><em><span class="dropcaps">F</span>irst</em> paragraph </p>',
149
            '<h2>H2 heading</h2>',
150
            '<p>Other first paragraph under H2</p>',
151
        );
152
153
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_LETTER, 1);
154
155
        // must change
156
        $dropCaps->createForFirstParagraph();
157
        $this->assertEquals(
158
             implode("", $expected),
159
             $dropCaps->getOutput()
160
        );
161
    }
162
163 View Code Duplication
    public function testWordMode()
164
    {
165
        $input = array(
166
            '<p>First (paragraph) in, the whole text.</p>',
167
            '<h2>H2 heading</h2>',
168
            '<p>Other first paragraph under H2</p>',
169
        );
170
171
        $expected = array(
172
            '<p class="has-dropcaps"><span class="dropcaps">First (paragraph) in,</span> the whole text.</p>',
173
            '<h2>H2 heading</h2>',
174
            '<p>Other first paragraph under H2</p>',
175
        );
176
177
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_WORD, 3);
178
179
        // must change
180
        $dropCaps->createForFirstParagraph();
181
        $this->assertEquals(
182
             implode("", $expected),
183
             $dropCaps->getOutput()
184
        );
185
    }
186
187 View Code Duplication
    public function testWordModeStartWithEntity()
188
    {
189
        $input = array(
190
            '<p>&raquo;First (paragraph) in, the whole text.</p>',
191
            '<h2>H2 heading</h2>',
192
            '<p>Other first paragraph under H2</p>',
193
        );
194
195
        $expected = array(
196
            '<p class="has-dropcaps"><span class="dropcaps">&raquo;First (paragraph)</span> in, the whole text.</p>',
197
            '<h2>H2 heading</h2>',
198
            '<p>Other first paragraph under H2</p>',
199
        );
200
201
        $dropCaps = new DropCaps(implode("", $input), DropCaps::MODE_WORD, 3);
202
203
        // must change
204
        $dropCaps->createForFirstParagraph();
205
        $this->assertEquals(
206
             implode("", $expected),
207
             $dropCaps->getOutput()
208
        );
209
    }
210
211
    public function testProcessManualMarkup()
212
    {
213
        $input = array(
214
            '<p><span class="dropcaps">This</span> has dropcaps.</p>',
215
        );
216
217
        $expected = array(
218
            '<p class="has-dropcaps"><span class="dropcaps">This</span> has dropcaps.</p>',
219
        );
220
221
        $dropCaps = new DropCaps(implode("", $input));
222
223
        // must change
224
        $dropCaps->processManualMarkup();
225
        $this->assertEquals(
226
             implode("", $expected),
227
             $dropCaps->getOutput()
228
        );
229
    }
230
231 View Code Duplication
    public function testMarkdownStyle()
232
    {
233
        $input = array(
234
            '<p>Normal paragraph.</p>',
235
            '<p>[[D]]rop caps paragraph.</p>',
236
            '<p>[[Another]] drop caps paragraph.</p>',
237
        );
238
239
        $expected = array(
240
            '<p>Normal paragraph.</p>',
241
            '<p class="has-dropcaps"><span class="dropcaps">D</span>rop caps paragraph.</p>',
242
            '<p class="has-dropcaps"><span class="dropcaps">Another</span> drop caps paragraph.</p>',
243
        );
244
245
        $dropCaps = new DropCaps(implode("", $input));
246
247
        // must change
248
        $dropCaps->createForMarkdownStyleMarkup();
249
        $this->assertEquals(
250
             implode("", $expected),
251
             $dropCaps->getOutput()
252
        );
253
    }
254
}
255