Skip to content

Commit

Permalink
Skip mixed in ParamTypeByMethodCallTypeRector as not specific
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 12, 2024
1 parent a775c65 commit 828e15b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;

final class SkipMixedAsNotPrecise
{
public function run($value)
{
$this->processArray($value);
}

private function processArray(mixed $value)
{
}
}
6 changes: 6 additions & 0 deletions rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PhpParser\Node\UnionType;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
Expand Down Expand Up @@ -48,6 +49,11 @@ public function matchCallParamType(
}

if (! $param->default instanceof Expr && ! $callParam->default instanceof Expr) {
$callParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($callParam->type);
if ($callParamType instanceof MixedType) {
return null;
}

return $callParam->type;
}

Expand Down
22 changes: 19 additions & 3 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Application;

use Nette\Utils\Strings;
use PHPStan\AnalysedCodeException;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
Expand All @@ -24,7 +25,6 @@
use Rector\ValueObject\Reporting\FileDiff;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;
use Nette\Utils\Strings;

final readonly class FileProcessor
{
Expand Down Expand Up @@ -150,13 +150,29 @@ private function printFile(File $file, Configuration $configuration, string $fil
* On very first content level
*/
$ltrimOriginalFileContent = ltrim($file->getOriginalFileContent());
if ($ltrimOriginalFileContent === $newContent) {

$originalFileContent = $file->getOriginalFileContent();
$ltrimOriginalFileContent = ltrim($originalFileContent);

// handle space before <?php
$ltrimNewContent = Strings::replace($newContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
$ltrimOriginalFileContent = Strings::replace(
$ltrimOriginalFileContent,
self::OPEN_TAG_SPACED_REGEX,
'<?php'
);

if ($ltrimOriginalFileContent === $ltrimNewContent) {
return;
}

// handle space before <?php
$ltrimNewContent = Strings::replace($newContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
$ltrimOriginalFileContent = Strings::replace($ltrimOriginalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
$ltrimOriginalFileContent = Strings::replace(
$ltrimOriginalFileContent,
self::OPEN_TAG_SPACED_REGEX,
'<?php'
);
if ($ltrimOriginalFileContent === $ltrimNewContent) {
return;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Autoloading/BootstrapFilesIncluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ private function requireRectorStubs(): void
return;
}

$dir = new RecursiveDirectoryIterator(
$stubsRectorDirectory,
RecursiveDirectoryIterator::SKIP_DOTS
);
$dir = new RecursiveDirectoryIterator($stubsRectorDirectory, RecursiveDirectoryIterator::SKIP_DOTS);

/** @var SplFileInfo[] $stubs */
$stubs = new RecursiveIteratorIterator($dir);

Expand Down

0 comments on commit 828e15b

Please sign in to comment.