Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deprecation] Add message about deprecated MixedTypeRector rule, Remove deprecated SetListInterface as no longer used #6590

Merged
merged 2 commits into from
Dec 14, 2024
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
82 changes: 5 additions & 77 deletions rules/Php80/Rector/FunctionLike/MixedTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover;
use Rector\FamilyTree\NodeAnalyzer\ClassChildAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -31,16 +22,6 @@
*/
final class MixedTypeRector extends AbstractRector implements MinPhpVersionInterface, DeprecatedInterface
{
private bool $hasChanged = false;

public function __construct(
private readonly ReflectionResolver $reflectionResolver,
private readonly ClassChildAnalyzer $classChildAnalyzer,
private readonly ParamTagRemover $paramTagRemover,
private readonly PhpDocInfoFactory $phpDocInfoFactory
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
Expand Down Expand Up @@ -85,67 +66,14 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node instanceof ClassMethod && $this->shouldSkipClassMethod($node)) {
return null;
}

$this->hasChanged = false;

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);

$this->refactorParamTypes($node, $phpDocInfo);
$hasChanged = $this->paramTagRemover->removeParamTagsIfUseless($phpDocInfo, $node, new MixedType());

if ($this->hasChanged || $hasChanged) {
return $node;
}

return null;
throw new ShouldNotHappenException(sprintf(
'The `%s` is removed. Use "typeDeclarations" set in rector.php instead, to avoid filling mixed on better known types.',
self::class
));
}

public function provideMinPhpVersion(): int
{
return PhpVersionFeature::MIXED_TYPE;
}

private function shouldSkipClassMethod(ClassMethod $classMethod): bool
{
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
if (! $classReflection instanceof ClassReflection) {
return false;
}

$methodName = $this->nodeNameResolver->getName($classMethod);
return $this->classChildAnalyzer->hasParentClassMethod($classReflection, $methodName);
}

private function refactorParamTypes(
ClassMethod | Function_ | Closure | ArrowFunction $functionLike,
PhpDocInfo $phpDocInfo
): void {
foreach ($functionLike->params as $param) {
if ($param->type instanceof Node) {
continue;
}

$paramName = (string) $this->getName($param->var);
$paramTagValue = $phpDocInfo->getParamTagValueByName($paramName);

if (! $paramTagValue instanceof ParamTagValueNode) {
continue;
}

$paramType = $phpDocInfo->getParamType($paramName);

if (! $paramType instanceof MixedType) {
continue;
}

$this->hasChanged = true;
$param->type = new Identifier('mixed');
if ($param->flags !== 0) {
$param->setAttribute(AttributeKey::ORIGINAL_NODE, null);
}
}
}
}
5 changes: 4 additions & 1 deletion src/Comments/NodeDocBlock/DocBlockUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ private function setCommentsAttribute(Node $node): void

private function clearEmptyDoc(Node $node): void
{
$comments = array_filter($node->getComments(), static fn (Comment $comment): bool => ! $comment instanceof Doc || $comment->getText() !== '');
$comments = array_filter(
$node->getComments(),
static fn (Comment $comment): bool => ! $comment instanceof Doc || $comment->getText() !== ''
);
$node->setAttribute(AttributeKey::COMMENTS, array_values($comments));
}

Expand Down
13 changes: 0 additions & 13 deletions src/Set/Contract/SetListInterface.php

This file was deleted.

Loading