Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fixer/PhpDocPropertySorterFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static function sortPropertiesByName(array &$properties): void
private static function extractPropertyName(string $propertyLine): ?string
{
$matches = [];
Preg::match('/@property\\s+[^\\s]+\\s+\\$(\\w+)/', $propertyLine, $matches);
Preg::match('/@property(?:-read|-write)?\\s+[^\\s]+\\s+\\$(\\w+)/', $propertyLine, $matches);
/** @var array<array-key, string> $matches */
if (\count($matches) > 1) {
return $matches[1];
Expand Down
17 changes: 17 additions & 0 deletions tests/Fixer/PhpDocPropertySorterFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,23 @@ function example($x) {}
* @return bool
*/
function example($x) {}
',
];

yield [
'<?php
/**
* @property bool $alpha
* @property-read array $beta
* @property-write Test $gamma
*/
',
'<?php
/**
* @property-read array $beta
* @property-write Test $gamma
* @property bool $alpha
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, will it break a groups of read and write? Can you add a test case with this as input:

/**
 * @property-write string $charlie
 * @property-write string $foxtrot
 * @property-write string $bravo
 * @property-read string $echo
 * @property-read string $delta
 * @property-read string $alfa
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is in place. Yes, it will break these groups. To keep the groups intact, you should add a blank line between them:

/**
 * @property-write string $charlie
 * @property-write string $foxtrot
 * @property-write string $bravo
 *
 * @property-read string $echo
 * @property-read string $delta
 * @property-read string $alfa
 */

',
];
}
Expand Down
Loading