Skip to content

Commit 6bc95ce

Browse files
committed
Merge branch '2.15' into 2.16
* 2.15: DX: Travis CI config - fix warnings and infos Fix handling `/**` and `*/` on the same line as the first and/or last annotation
2 parents ddd873e + d3ac7c1 commit 6bc95ce

File tree

4 files changed

+113
-4
lines changed

4 files changed

+113
-4
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
dist: xenial
2+
os: linux
3+
14
language: php
25

36
git:
@@ -145,10 +148,10 @@ jobs:
145148
- test $(php dev-tools/info-extractor.php | jq .version.vnumber) == "\"$TRAVIS_TAG\""
146149
deploy:
147150
provider: releases
148-
api_key:
151+
token:
149152
secure: K9NKi7X1OPz898fxtVc1RfWrSI+4hTFFYOik932wTz1jC4dQJ64Khh1LV9frA1+JiDS3+R6TvmQtpzbkX3y4L75UrSnP1ADH5wfMYIVmydG3ZjTMo8SWQWHmRMh3ORAKTMMpjl4Q7EkRkLp6RncKe+FAFPP5mgv55mtIMaE4qUk=
150153
file: php-cs-fixer.phar
151-
skip_cleanup: true
154+
cleanup : false
152155
on:
153156
repo: FriendsOfPHP/PHP-CS-Fixer
154157
tags: true

src/DocBlock/Annotation.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,23 @@ public function getNormalizedTypes()
248248
public function remove()
249249
{
250250
foreach ($this->lines as $line) {
251-
$line->remove();
251+
if ($line->isTheStart() && $line->isTheEnd()) {
252+
// Single line doc block, remove entirely
253+
$line->remove();
254+
} elseif ($line->isTheStart()) {
255+
// Multi line doc block, but start is on the same line as the first annotation, keep only the start
256+
$content = Preg::replace('#(\s*/\*\*).*#', '$1', $line->getContent());
257+
258+
$line->setContent($content);
259+
} elseif ($line->isTheEnd()) {
260+
// Multi line doc block, but end is on the same line as the last annotation, keep only the end
261+
$content = Preg::replace('#(\s*)\S.*(\*/.*)#', '$1$2', $line->getContent());
262+
263+
$line->setContent($content);
264+
} else {
265+
// Multi line doc block, neither start nor end on this line, can be removed safely
266+
$line->remove();
267+
}
252268
}
253269

254270
$this->clearCache();
@@ -286,7 +302,7 @@ private function getTypesContent()
286302
}
287303

288304
$matchingResult = Preg::match(
289-
'{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:\h.*)?$}sx',
305+
'{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[*\h].*)?$}sx',
290306
$this->lines[0]->getContent(),
291307
$matches
292308
);

tests/DocBlock/AnnotationTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,58 @@ public function provideRemoveCases()
213213
return $cases;
214214
}
215215

216+
/**
217+
* @param string $expected
218+
* @param string $input
219+
*
220+
* @dataProvider provideRemoveEdgeCasesCases
221+
*/
222+
public function testRemoveEdgeCases($expected, $input)
223+
{
224+
$doc = new DocBlock($input);
225+
$annotation = $doc->getAnnotation(0);
226+
227+
$annotation->remove();
228+
static::assertSame($expected, $doc->getContent());
229+
}
230+
231+
public function provideRemoveEdgeCasesCases()
232+
{
233+
return [
234+
// Single line
235+
['', '/** @return null*/'],
236+
['', '/** @return null */'],
237+
['', '/** @return null */'],
238+
239+
// Multi line, annotation on start line
240+
[
241+
'/**
242+
*/',
243+
'/** @return null
244+
*/',
245+
],
246+
[
247+
'/**
248+
*/',
249+
'/** @return null '.'
250+
*/',
251+
],
252+
// Multi line, annotation on end line
253+
[
254+
'/**
255+
*/',
256+
'/**
257+
* @return null*/',
258+
],
259+
[
260+
'/**
261+
*/',
262+
'/**
263+
* @return null */',
264+
],
265+
];
266+
}
267+
216268
/**
217269
* @param string $input
218270
* @param string[] $expected

tests/Fixer/Phpdoc/PhpdocNoEmptyReturnFixerTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,44 @@ public function testFixNull()
5858
* @return null
5959
*/
6060

61+
EOF;
62+
63+
$this->doTest($expected, $input);
64+
}
65+
66+
public function testFixNullWithEndOnSameLine()
67+
{
68+
$expected = <<<'EOF'
69+
<?php
70+
/**
71+
*/
72+
73+
EOF;
74+
75+
$input = <<<'EOF'
76+
<?php
77+
/**
78+
* @return null */
79+
80+
EOF;
81+
82+
$this->doTest($expected, $input);
83+
}
84+
85+
public function testFixNullWithEndOnSameLineNoSpace()
86+
{
87+
$expected = <<<'EOF'
88+
<?php
89+
/**
90+
*/
91+
92+
EOF;
93+
94+
$input = <<<'EOF'
95+
<?php
96+
/**
97+
* @return null*/
98+
6199
EOF;
62100

63101
$this->doTest($expected, $input);

0 commit comments

Comments
 (0)