Skip to content

Commit

Permalink
only make typed with use doc @param mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jul 24, 2022
1 parent 8e87c31 commit bd6803e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 148 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<?php

declare(strict_types=1);
namespace Rector\Tests\Php80\Rector\FunctionLike\MixedTypeRector\Fixture;

namespace Rector\Tests\Php80\Rector\FunctionLike\MixedTypeRector\Source;

class SomeParentWithNonMixedDoc
class NoMixedParamDoc
{
/**
* @param int $param
*/
public function run($param)
{
}
}
}

This file was deleted.

70 changes: 0 additions & 70 deletions rules/Php80/Guard/MakeClassMethodParamMixedTypedGuard.php

This file was deleted.

16 changes: 7 additions & 9 deletions rules/Php80/Rector/FunctionLike/MixedTypeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\PhpDoc\TagRemover\ParamTagRemover;
use Rector\Php80\Guard\MakeClassMethodParamMixedTypedGuard;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -28,8 +28,7 @@ final class MixedTypeRector extends AbstractRector implements MinPhpVersionInter
private bool $hasChanged = false;

public function __construct(
private readonly ParamTagRemover $paramTagRemover,
private readonly MakeClassMethodParamMixedTypedGuard $makeClassMethodParamMixedTypedGuard
private readonly ParamTagRemover $paramTagRemover
) {
}

Expand Down Expand Up @@ -102,19 +101,18 @@ private function refactorParamTypes(
ClassMethod | Function_ | Closure | ArrowFunction $functionLike,
PhpDocInfo $phpDocInfo
): void {
foreach ($functionLike->params as $keyParam => $param) {
foreach ($functionLike->params as $param) {
if ($param->type instanceof Node) {
continue;
}

if ($functionLike instanceof ClassMethod && ! $this->makeClassMethodParamMixedTypedGuard->isLegal(
$functionLike,
$keyParam
)) {
$paramName = (string) $this->getName($param->var);
$paramTagValue = $phpDocInfo->getParamTagValueByName($paramName);

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

$paramName = (string) $this->getName($param->var);
$paramType = $phpDocInfo->getParamType($paramName);

if (! $paramType instanceof MixedType) {
Expand Down

0 comments on commit bd6803e

Please sign in to comment.