Skip to content

Commit f0e50ed

Browse files
committed
make annotation splitting more clever using wordwrap in order to keep
words complete and remove useless spaces at line starting and ending
1 parent 95c1884 commit f0e50ed

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Element/PhpAnnotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function getPhpContent()
6565
$fullContent,
6666
);
6767
if (strlen($fullContent) > $this->getMaxLength()) {
68-
$content = str_split($fullContent, $this->getMaxLength());
68+
$content = explode(self::BREAK_LINE_CHAR, wordwrap($fullContent, $this->getMaxLength(), self::BREAK_LINE_CHAR, true));
6969
}
7070
return array_map(function ($element) {
7171
return sprintf(' %s', $element);

Tests/Component/PhpClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function testSimpleToString()
2121
->addAnnotationBlock(new PhpAnnotationElement('var', 'int'))
2222
->addProperty('bar', 1)
2323
->addAnnotationBlock(array(
24-
'- documentation: The ID of the contact that performed the action, if available.-May be blank for anonymous activity.',
24+
'- documentation: The ID of the contact that performed the action, if available. May be blank for anonymous activity.',
2525
new PhpAnnotationElement('var', 'bool'),
2626
))
2727
->addPropertyElement(new PhpPropertyElement('sample', true))

Tests/Element/PhpAnnotationBlockTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function testGetSeveralLinesToString()
3535

3636
$this->assertSame("/**\n" .
3737
" * This sample annotation is on one line This sample annotation is on one line This\n" .
38-
" * sample annotation is on one line This sample annotation is on one line This sam\n" .
39-
" * ple annotation is on one line This sample annotation is on one line This sample \n" .
40-
" * annotation is on one line\n" .
38+
" * sample annotation is on one line This sample annotation is on one line This\n" .
39+
" * sample annotation is on one line This sample annotation is on one line This\n" .
40+
" * sample annotation is on one line\n" .
4141
" */", $annotationBlock->toString());
4242
}
4343

@@ -48,10 +48,10 @@ public function testGetSeveralLinesWithNameToString()
4848
));
4949

5050
$this->assertSame("/**\n" .
51-
" * @description This sample annotation is on one line This sample annotation is on \n" .
52-
" * one line This sample annotation is on one line This sample annotation is on one \n" .
51+
" * @description This sample annotation is on one line This sample annotation is on\n" .
52+
" * one line This sample annotation is on one line This sample annotation is on one\n" .
5353
" * line This sample annotation is on one line This sample annotation is on one line\n" .
54-
" * This sample annotation is on one line\n" .
54+
" * This sample annotation is on one line\n" .
5555
" */", $annotationBlock->toString());
5656
}
5757

@@ -96,10 +96,10 @@ public function testToStringSeveralLinesWithNameToString()
9696
));
9797

9898
$this->assertSame("/**\n" .
99-
" * @description This sample annotation is on one line This sample annotation is on \n" .
100-
" * one line This sample annotation is on one line This sample annotation is on one \n" .
99+
" * @description This sample annotation is on one line This sample annotation is on\n" .
100+
" * one line This sample annotation is on one line This sample annotation is on one\n" .
101101
" * line This sample annotation is on one line This sample annotation is on one line\n" .
102-
" * This sample annotation is on one line\n" .
102+
" * This sample annotation is on one line\n" .
103103
" */", $annotationBlock->toString());
104104
}
105105

Tests/Element/PhpAnnotationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ public function testGetSeveralLinesPhpDeclaration()
2626
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, str_repeat('This sample annotation is on one line ', 7));
2727

2828
$this->assertSame(" * This sample annotation is on one line This sample annotation is on one line This\n" .
29-
" * sample annotation is on one line This sample annotation is on one line This sam\n" .
30-
" * ple annotation is on one line This sample annotation is on one line This sample \n" .
31-
" * annotation is on one line", $annotation->getPhpDeclaration());
29+
" * sample annotation is on one line This sample annotation is on one line This\n" .
30+
" * sample annotation is on one line This sample annotation is on one line This\n" .
31+
" * sample annotation is on one line", $annotation->getPhpDeclaration());
3232
}
3333

3434
public function testGetSeveralLinesWithNamePhpDeclaration()
3535
{
3636
$annotation = new PhpAnnotation('description', str_repeat('This sample annotation is on one line ', 7));
3737

38-
$this->assertSame(" * @description This sample annotation is on one line This sample annotation is on \n" .
39-
" * one line This sample annotation is on one line This sample annotation is on one \n" .
38+
$this->assertSame(" * @description This sample annotation is on one line This sample annotation is on\n" .
39+
" * one line This sample annotation is on one line This sample annotation is on one\n" .
4040
" * line This sample annotation is on one line This sample annotation is on one line\n" .
41-
" * This sample annotation is on one line", $annotation->getPhpDeclaration());
41+
" * This sample annotation is on one line", $annotation->getPhpDeclaration());
4242
}
4343

4444
public function testGetSeveralLinesLargerWithNamePhpDeclaration()

Tests/resources/PhpClassTest_SimpleToString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class Foo extends stdClass
1313
*/
1414
public $bar = 1;
1515
/**
16-
* - documentation: The ID of the contact that performed the action, if available.-
16+
* - documentation: The ID of the contact that performed the action, if available.
1717
* May be blank for anonymous activity.
1818
* @var bool
1919
*/

0 commit comments

Comments
 (0)