Skip to content

Commit be3ff0d

Browse files
committed
Extend PhpDocPropertySorterFixer to support @property-read and @property-write
1 parent 086e46d commit be3ff0d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Fixer/PhpDocPropertySorterFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static function sortPropertiesByName(array &$properties): void
126126
private static function extractPropertyName(string $propertyLine): ?string
127127
{
128128
$matches = [];
129-
Preg::match('/@property\\s+[^\\s]+\\s+\\$(\\w+)/', $propertyLine, $matches);
129+
Preg::match('/@property(?:-read|-write)?\\s+[^\\s]+\\s+\\$(\\w+)/', $propertyLine, $matches);
130130
/** @var array<array-key, string> $matches */
131131
if (\count($matches) > 1) {
132132
return $matches[1];

tests/Fixer/PhpDocPropertySorterFixerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ function example($x) {}
183183
* @return bool
184184
*/
185185
function example($x) {}
186+
',
187+
];
188+
189+
yield [
190+
'<?php
191+
/**
192+
* @property bool $alpha
193+
* @property-read array $beta
194+
* @property-write Test $gamma
195+
*/
196+
',
197+
'<?php
198+
/**
199+
* @property-read array $beta
200+
* @property-write Test $gamma
201+
* @property bool $alpha
202+
*/
186203
',
187204
];
188205
}

0 commit comments

Comments
 (0)