Merge pull request #2999 from rectorphp/fix-example-doc

wontfix test case
This commit is contained in:
Tomas Votruba 2020-03-03 17:28:22 +01:00 committed by GitHub
commit c9a5b6d160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 33 deletions

View File

@ -121,10 +121,7 @@
"Rector\\TypeDeclaration\\": "rules/type-declaration/src",
"Rector\\VendorLocker\\": "packages/vendor-locker/src",
"Rector\\ZendToSymfony\\": "rules/zend-to-symfony/src"
},
"files": [
"src/functions/rector_dump_function.php"
]
}
},
"autoload-dev": {
"psr-4": {

View File

@ -115,9 +115,7 @@ final class PhpDocInfoPrinter
$this->removedNodePositions = [];
$phpDocString = $this->printPhpDocNode($this->attributeAwarePhpDocNode);
// replace extra space after *
$phpDocString = Strings::replace($phpDocString, '#([^*])\*[ \t]+$#sm', '$1*');
$phpDocString = $this->removeExtraSpacesAfterAsterisk($phpDocString);
// hotfix of extra space with callable ()
return Strings::replace($phpDocString, '#callable(\s+)\(#', 'callable(');
@ -297,9 +295,8 @@ final class PhpDocInfoPrinter
private function printAttributeWithAsterisk(AttributeAwareNodeInterface $attributeAwareNode): string
{
$content = (string) $attributeAwareNode;
$content = explode(PHP_EOL, $content);
return implode(self::NEWLINE_ASTERISK, $content);
return $this->explodeAndImplode($content, PHP_EOL, self::NEWLINE_ASTERISK);
}
/**
@ -380,4 +377,20 @@ final class PhpDocInfoPrinter
return (bool) $attributeAwarePhpDocTagNode->value->description;
}
private function explodeAndImplode(string $content, string $explodeChar, string $implodeChar): string
{
$content = explode($explodeChar, $content);
if (! is_array($content)) {
throw new ShouldNotHappenException();
}
return implode($implodeChar, $content);
}
private function removeExtraSpacesAfterAsterisk(string $phpDocString): string
{
return Strings::replace($phpDocString, '#([^*])\*[ \t]+$#sm', '$1*');
}
}

View File

@ -21,8 +21,10 @@ final class SpacePatternFactory
// we have to match exact @param space, in case of multiple @param s
if ($phpDocTagNode->value instanceof AttributeAwareParamTagValueNode) {
$spacePattern = $this->createSpacePatternForParamTagValueNode($phpDocTagNode->value, $spacePattern);
} elseif ($phpDocTagNode->value instanceof AttributeAwareGenericTagValueNode) {
return $this->createSpacePatternForParamTagValueNode($phpDocTagNode->value, $spacePattern);
}
if ($phpDocTagNode->value instanceof AttributeAwareGenericTagValueNode) {
$originalValue = $phpDocTagNode->value->getAttribute('original_value') ?? $phpDocTagNode->value->value;
// break by line break, to prevent false content positive
@ -56,6 +58,7 @@ final class SpacePatternFactory
$spacePattern .= preg_quote($attributeAwareParamTagValueNode->parameterName, '#');
}
return $spacePattern;
return '#' . $spacePattern . '#';
}
}

View File

@ -0,0 +1,11 @@
/**
* ```
* SomeClass::someMethod('default'
* );
* ```
*
* ```
* SomeClass::someMethod(
* );
* ```
*/

View File

@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
use Tracy\Debugger;
if (! function_exists('rd')) {
function rd($var)
{
array_map([Debugger::class, 'dump'], func_get_args());
return $var;
}
}
if (! function_exists('rdd')) {
function rdd($var): void
{
rd($var);
die;
}
}