Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"bin": ["bin/rector"],
"require": {
"php": "^7.2",
"php": "^7.2.3",
"ext-json": "*",
"composer/xdebug-handler": "^1.4",
"doctrine/annotations": "^1.8",
Expand All @@ -29,20 +29,20 @@
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0",
"symfony/process": "^4.4|^5.0",
"symplify/auto-bind-parameter": "^7.2",
"symplify/autowire-array-parameter": "^7.2",
"symplify/package-builder": "^7.2",
"symplify/set-config-resolver": "^7.2",
"symplify/auto-bind-parameter": "^7.2.3",
"symplify/autowire-array-parameter": "^7.2.3",
"symplify/package-builder": "^7.2.3",
"symplify/set-config-resolver": "^7.2.3",
"tracy/tracy": "^2.7"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"ocramius/package-versions": "^1.4|^1.5",
"phpunit/phpunit": "^8.4|^9.0",
"symplify/changelog-linker": "^7.2",
"symplify/easy-coding-standard": "^7.2",
"symplify/monorepo-builder": "^7.2",
"symplify/phpstan-extensions": "^7.2",
"symplify/changelog-linker": "^7.2.3",
"symplify/easy-coding-standard": "^7.2.3",
"symplify/monorepo-builder": "^7.2.3",
"symplify/phpstan-extensions": "^7.2.3",
"thecodingmachine/phpstan-strict-rules": "^0.12"
},
"replace": {
Expand Down
7 changes: 7 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
services:
Symplify\CodingStandard\Sniffs\CleanCode\ClassCognitiveComplexitySniff:
max_class_cognitive_complexity: 110

Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
max_cognitive_complexity: 9

Expand Down Expand Up @@ -81,6 +84,10 @@ parameters:
# hidden API
- 'src/Rector/AbstractRector.php'

Symplify\CodingStandard\Sniffs\CleanCode\ClassCognitiveComplexitySniff:
# node printing
- 'utils/documentation-generator/src/Command/DumpNodesCommand.php'

Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
# todo
- "packages/better-php-doc-parser/src/Printer/WhitespaceDetector.php"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Rector\AttributeAwarePhpDoc\Ast\Type;

use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait;
use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface;
Expand All @@ -12,11 +14,30 @@ final class AttributeAwareUnionTypeNode extends UnionTypeNode implements Attribu
{
use AttributeTrait;

/**
* @var bool
*/
private $isWrappedWithBrackets = false;

/**
* @param TypeNode[] $types
*/
public function __construct(array $types, string $originalContent = '')
{
parent::__construct($types);

$this->isWrappedWithBrackets = (bool) Strings::match($originalContent, '#^\((.*?)\)#');
}

/**
* Preserve common format
*/
public function __toString(): string
{
return implode('|', $this->types);
if (! $this->isWrappedWithBrackets) {
return implode('|', $this->types);
}

return '(' . implode('|', $this->types) . ')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param DeprecatedTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareDeprecatedTagValueNode($node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ExtendsTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareExtendsTagValueNode($node->type, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param GenericTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareGenericTagValueNode($node->value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ImplementsTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareImplementsTagValueNode($node->type, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param InvalidTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareInvalidTagValueNode($node->value, $node->exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function isMatch(Node $node): bool
/**
* @param MethodTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$returnType = $this->createAttributeAwareReturnType($node);
$returnType = $this->createAttributeAwareReturnType($node, $docContent);

return new AttributeAwareMethodTagValueNode(
$node->isStatic,
Expand All @@ -54,10 +54,10 @@ public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attribut
/**
* @return TypeNode&AttributeAwareNodeInterface
*/
private function createAttributeAwareReturnType(MethodTagValueNode $methodTagValueNode)
private function createAttributeAwareReturnType(MethodTagValueNode $methodTagValueNode, string $docContent)
{
if ($methodTagValueNode->returnType !== null) {
return $this->attributeAwareNodeFactory->createFromNode($methodTagValueNode->returnType);
return $this->attributeAwareNodeFactory->createFromNode($methodTagValueNode->returnType, $docContent);
}

return $methodTagValueNode->returnType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function isMatch(Node $node): bool
/**
* @param MethodTagValueParameterNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
if ($node->type !== null) {
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);
}

return new AttributeAwareMethodTagValueParameterNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ParamTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareParamTagValueNode(
$node->type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ public function isMatch(Node $node): bool
/**
* @param PhpDocNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$this->phpDocNodeTraverser->traverseWithCallable($node, function (Node $node): AttributeAwareNodeInterface {
$this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (Node $node) use (
$docContent
): AttributeAwareNodeInterface {
if ($node instanceof AttributeAwareNodeInterface) {
return $node;
}

return $this->attributeAwareNodeFactory->createFromNode($node);
return $this->attributeAwareNodeFactory->createFromNode($node, $docContent);
});

return new AttributeAwarePhpDocNode($node->children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param PhpDocTagNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwarePhpDocTagNode($node->name, $node->value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param PhpDocTextNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwarePhpDocTextNode($node->text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param PropertyTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwarePropertyTagValueNode($node->type, $node->propertyName, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ReturnTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareReturnTagValueNode($node->type, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param TemplateTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareTemplateTagValueNode($node->name, $node->bound, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ThrowsTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareThrowsTagValueNode($node->type, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param UsesTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareUsesTagValueNode($node->type, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param VarTagValueNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareVarTagValueNode($node->type, $node->variableName, $node->description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param ArrayShapeItemNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param ArrayShapeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareArrayShapeNode($node->items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function isMatch(Node $node): bool
/**
* @param ArrayTypeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

return new AttributeAwareArrayTypeNode($node->type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function isMatch(Node $node): bool
/**
* @param CallableTypeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$identifier = $this->attributeAwareNodeFactory->createFromNode($node->identifier);
$identifier = $this->attributeAwareNodeFactory->createFromNode($node->identifier, $docContent);

foreach ($node->parameters as $key => $parameter) {
$node->parameters[$key] = $this->attributeAwareNodeFactory->createFromNode($parameter);
$node->parameters[$key] = $this->attributeAwareNodeFactory->createFromNode($parameter, $docContent);
}

$returnType = $this->attributeAwareNodeFactory->createFromNode($node->returnType);
$returnType = $this->attributeAwareNodeFactory->createFromNode($node->returnType, $docContent);

return new AttributeAwareCallableTypeNode($identifier, $node->parameters, $returnType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param CallableTypeParameterNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareCallableTypeParameterNode(
$node->type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public function isMatch(Node $node): bool
/**
* @param GenericTypeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type);
$node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent);

foreach ($node->genericTypes as $key => $genericType) {
$node->genericTypes[$key] = $this->attributeAwareNodeFactory->createFromNode($genericType);
$node->genericTypes[$key] = $this->attributeAwareNodeFactory->createFromNode($genericType, $docContent);
}

return new AttributeAwareGenericTypeNode($node->type, $node->genericTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function isMatch(Node $node): bool
/**
* @param IdentifierTypeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
return new AttributeAwareIdentifierTypeNode($node->name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function isMatch(Node $node): bool
/**
* @param IntersectionTypeNode $node
*/
public function create(Node $node): AttributeAwareNodeInterface
public function create(Node $node, string $docContent): AttributeAwareNodeInterface
{
foreach ($node->types as $key => $intersectionedType) {
$node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($intersectionedType);
$node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($intersectionedType, $docContent);
}

return new AttributeAwareIntersectionTypeNode($node->types);
Expand Down
Loading