Compare commits

...
6 Commits
Author SHA1 Message Date
Barry vd. Heuvel 4f5ba70c30 Remove cron schedule from run-tests.yml
Removed scheduled cron job from workflow.
2026-03-05 21:09:01 +01:00
isaackaara 700b4e071f fix: Remove trailing spaces from empty docblock lines (#30)
When DocBlock text contains empty lines, str_replace replaces each newline
with a newline followed by ' * ', producing ' * ' (with trailing space) for
empty lines. This triggers trailing-whitespace linters.

Added a preg_replace after each str_replace call to strip trailing horizontal
whitespace from lines that consist only of ' *' followed by spaces.
2026-03-05 12:30:11 +01:00
Joey Richard d103774cbe Correcting an issue where there are two empty lines, first with an extra space, when there is no text to display on the first line. (#29) 2025-07-17 08:07:30 +02:00
func0der 5a3e22c213 trim_empty_docblock_whitespaces Trim whitespaces from phpdocs without content (#28) 2025-06-19 15:09:12 +02:00
Nereo Berardozzi b6ff9f9360 Fixed parsing of string literals and array shapes (#27) 2025-01-18 20:26:32 +01:00
Nereo Berardozzi ffb733ef78 Fixed callable types parsing (#26) 2024-12-30 19:14:26 +01:00
8 changed files with 74 additions and 15 deletions
-2
View File
@@ -7,8 +7,6 @@ on:
pull_request: pull_request:
branches: branches:
- "*" - "*"
schedule:
- cron: '0 0 * * *'
jobs: jobs:
php-tests: php-tests:
@@ -206,8 +206,9 @@ class Serializer
$text = wordwrap($text, $wrapLength); $text = wordwrap($text, $wrapLength);
} }
$text = str_replace("\n", "\n{$indent} * ", $text); $text = str_replace("\n", "\n{$indent} * ", $text);
$text = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $text);
$comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n"; $comment = !empty($text)? "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n" : "{$firstIndent}/**\n";
$tags = array_values($docblock->getTags()); $tags = array_values($docblock->getTags());
@@ -220,6 +221,7 @@ class Serializer
$tagText = wordwrap($tagText, $wrapLength); $tagText = wordwrap($tagText, $wrapLength);
} }
$tagText = str_replace("\n", "\n{$indent} * ", $tagText); $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
$tagText = preg_replace('/^(\s*\*)[ \t]+$/m', '$1', $tagText);
$comment .= "{$indent} * {$tagText}\n"; $comment .= "{$indent} * {$tagText}\n";
+1 -1
View File
@@ -409,6 +409,6 @@ class Tag implements \Reflector
*/ */
public function __toString() public function __toString()
{ {
return "@{$this->getName()} {$this->getContent()}"; return trim("@{$this->getName()} {$this->getContent()}");
} }
} }
@@ -54,16 +54,15 @@ class ParamTag extends ReturnTag
for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) { for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
$char = $rest[$pos]; $char = $rest[$pos];
if($char === '<') { if(in_array($char, ['<', '(', '[', '{'])) {
array_unshift($stacks, $char); array_unshift($stacks, $char);
} }
if($char === '(') { if(
array_unshift($stacks, $char); ($char === '>' && isset($stacks[0]) && $stacks[0] === '<')
} || ($char === ')' && isset($stacks[0]) && $stacks[0] === '(')
if($char === '>' && isset($stacks[0]) && $stacks[0] === '<') { || ($char === ']' && isset($stacks[0]) && $stacks[0] === '[')
array_shift($stacks); || ($char === '}' && isset($stacks[0]) && $stacks[0] === '{')
} ) {
if($char === ')' && isset($stacks[0]) && $stacks[0] === '(') {
array_shift($stacks); array_shift($stacks);
} }
@@ -161,9 +161,9 @@ class Collection extends \ArrayObject
$type_parts[] = $curr_type; $type_parts[] = $curr_type;
$curr_type = ''; $curr_type = '';
} else { } else {
if ($char === '<' || $char === '(') { if (in_array($char, ['<', '(', '[', '{'])) {
$nest_level++; $nest_level++;
} else if ($char === '>' || $char === ')') { } else if (in_array($char, ['>', ')', ']', '}'])) {
$nest_level--; $nest_level--;
} }
@@ -201,7 +201,13 @@ class Collection extends \ArrayObject
return ''; return '';
} }
if (preg_match('/^[\w-]+<.*>$/', $type)) { // Check for generics values and array shapes
if (preg_match('/^[\w-]+(<.+>|\[.+\]|{.+})$/', $type)) {
return $type;
}
// Check for callable types
if (preg_match('/\(.*?(?=\:)/', $type)) {
return $type; return $type;
} }
@@ -209,6 +215,11 @@ class Collection extends \ArrayObject
return $type; return $type;
} }
// Literal strings
if ($type[0] === '"' || $type[0] === "'") {
return $type;
}
if ($this->isTypeAnArray($type)) { if ($this->isTypeAnArray($type)) {
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY; return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
} }
@@ -183,6 +183,24 @@ class ParamTagTest extends TestCase
'$callback', '$callback',
'' ''
), ),
// array shapes
array(
'param',
'array{foo: string, bar: int} $array',
'array{foo: string, bar: int}',
array('array{foo: string, bar: int}'),
'$array',
''
),
array(
'param',
'MyArray[\'key\'] $value',
'MyArray[\'key\']',
array('MyArray[\'key\']'),
'$value',
''
)
); );
} }
} }
@@ -119,6 +119,13 @@ class ReturnTagTest extends TestCase
'array<int, string|bool>|string', 'array<int, string|bool>|string',
array('array<int, string|bool>', 'string'), array('array<int, string|bool>', 'string'),
'Types of Bobs' 'Types of Bobs'
),
array(
'return',
'MyArray[\'key\'] Type of Bobs',
'MyArray[\'key\']',
array('MyArray[\'key\']'),
'Type of Bobs'
) )
); );
} }
@@ -239,6 +239,18 @@ class CollectionTest extends TestCase
'array<int, string|array<int, bool>>|array<int, float>|string', 'array<int, string|array<int, bool>>|array<int, float>|string',
array('array<int, string|array<int, bool>>', 'array<int, float>', 'string') array('array<int, string|array<int, bool>>', 'array<int, float>', 'string')
), ),
array(
'array{ 0: string, 1: string|int }',
array('array{ 0: string, 1: string|int }')
),
array(
"array{ 'key': string, 'value': string|int }",
array("array{ 'key': string, 'value': string|int }")
),
array(
"MyArray['bar']",
array("MyArray['bar']")
),
array( array(
'LinkDescriptor::setLink()', 'LinkDescriptor::setLink()',
array($namespace.'LinkDescriptor::setLink()') array($namespace.'LinkDescriptor::setLink()')
@@ -283,6 +295,18 @@ class CollectionTest extends TestCase
'iterable<string>', 'iterable<string>',
array('iterable<string>') array('iterable<string>')
), ),
array(
'callable',
array('callable')
),
array(
'callable(int, string): int',
array('callable(int, string): int')
),
array(
"'text'",
array("'text'")
)
); );
} }