-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.17: TypeAlternationTransformer - add support for PHP8 Enhancement: Allow sorting of property, property-read, and property-write annotations by value Enhancement: Allow sorting of method annotations by value NoExtraBlankLinesFixer - PHP8 throw support minors NullableTypeTransformer - constructor property promotion support TokensAnalyzer::getClassyElements - return trait imports SingleSpaceAfterConstructFixer - Attributes, comments and PHPDoc support Fix: Description
- Loading branch information
Showing
29 changed files
with
1,084 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
use PhpCsFixer\Preg; | ||
use PhpCsFixer\Tokenizer\Token; | ||
use PhpCsFixer\Tokenizer\Tokens; | ||
use Symfony\Component\OptionsResolver\Options; | ||
|
||
/** | ||
* @author Filippo Tessarotto <[email protected]> | ||
|
@@ -96,7 +97,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) | |
} | ||
|
||
for ($index = $tokens->count() - 1; $index > 0; --$index) { | ||
foreach ($this->configuration['annotations'] as $type) { | ||
foreach ($this->configuration['annotations'] as $type => $typeLowerCase) { | ||
$findPattern = sprintf( | ||
'/@%s\s.+@%s\s/s', | ||
$type, | ||
|
@@ -113,20 +114,33 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) | |
$docBlock = new DocBlock($tokens[$index]->getContent()); | ||
|
||
$annotations = $docBlock->getAnnotationsOfType($type); | ||
|
||
$annotationMap = []; | ||
|
||
$replacePattern = sprintf( | ||
'/\*\s*@%s\s+(.+)/', | ||
$type | ||
); | ||
if (\in_array($type, ['property', 'property-read', 'property-write'], true)) { | ||
$replacePattern = sprintf( | ||
'/(?s)\*\s*@%s\s+(?P<optionalTypes>.+\s+)?\$(?P<comparableContent>[^\s]+).*/', | ||
$type | ||
); | ||
|
||
$replacement = '\2'; | ||
} elseif ('method' === $type) { | ||
$replacePattern = '/(?s)\*\s*@method\s+(?P<optionalReturnTypes>.+\s+)?(?P<comparableContent>.+)\(.*/'; | ||
$replacement = '\2'; | ||
} else { | ||
$replacePattern = sprintf( | ||
'/\*\s*@%s\s+(?P<comparableContent>.+)/', | ||
$typeLowerCase | ||
); | ||
|
||
$replacement = '\1'; | ||
} | ||
|
||
foreach ($annotations as $annotation) { | ||
$rawContent = $annotation->getContent(); | ||
|
||
$comparableContent = Preg::replace( | ||
$replacePattern, | ||
'\1', | ||
$replacement, | ||
strtolower(trim($rawContent)) | ||
); | ||
|
||
|
@@ -167,6 +181,10 @@ protected function createConfigurationDefinition() | |
'depends', | ||
'group', | ||
'internal', | ||
'method', | ||
'property', | ||
'property-read', | ||
'property-write', | ||
'requires', | ||
'throws', | ||
'uses', | ||
|
@@ -180,6 +198,17 @@ protected function createConfigurationDefinition() | |
->setAllowedValues([ | ||
new AllowedValueSubset($allowedValues), | ||
]) | ||
->setNormalizer(function (Options $options, $value) { | ||
$normalized = []; | ||
|
||
foreach ($value as $index => $annotation) { | ||
// since we will be using strtolower on the input annotations when building the sorting | ||
// map we must match the type in lower case as well | ||
$normalized[$annotation] = strtolower($annotation); | ||
} | ||
|
||
return $normalized; | ||
}) | ||
->setDefault([ | ||
'covers', | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.