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

Update rector v0.15.1 #3227

Merged
merged 2 commits into from
Dec 19, 2022
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"helmich/typo3-typoscript-parser": "^2.4.1",
"nette/utils": "^3.0",
"nikic/php-parser": "^4.14",
"phpstan/phpstan": "1.9.2",
"rector/rector": "0.14.8",
"phpstan/phpstan": "^1.7.12",
"rector/rector": "0.15.1",
"symfony/console": "^4.0 || ^5.0 || ^6.0",
"symfony/polyfill-php80": "^1.26",
"symfony/polyfill-php81": "^1.26",
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@
'*/Fixture/*',
]);

$rectorConfig->rule(TypedPropertyRector::class);
$rectorConfig->rule(ClassPropertyAssignToConstructorPromotionRector::class);
};
6 changes: 3 additions & 3 deletions src/NodeFactory/InitializeArgumentsClassMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Rector\TypeDeclaration\TypeInferer\ParamTypeInferer;
use Ssch\TYPO3Rector\TypeInferer\ParamTypeInferer\FunctionLikeDocParamTypeInferer;

final class InitializeArgumentsClassMethodFactory
{
Expand Down Expand Up @@ -73,7 +73,7 @@ final class InitializeArgumentsClassMethodFactory
/**
* @readonly
*/
private ParamTypeInferer $paramTypeInferer;
private FunctionLikeDocParamTypeInferer $paramTypeInferer;

/**
* @readonly
Expand All @@ -99,7 +99,7 @@ public function __construct(
NodeFactory $nodeFactory,
NodeNameResolver $nodeNameResolver,
StaticTypeMapper $staticTypeMapper,
ParamTypeInferer $paramTypeInferer,
FunctionLikeDocParamTypeInferer $paramTypeInferer,
PhpDocInfoFactory $phpDocInfoFactory,
ReflectionProvider $reflectionProvider,
ValueResolver $valueResolver,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\TypeInferer\ParamTypeInferer;

use PhpParser\Node;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeNameResolver\NodeNameResolver;

final class FunctionLikeDocParamTypeInferer
{
/**
* @readonly
*/
private NodeNameResolver $nodeNameResolver;

/**
* @readonly
*/
private PhpDocInfoFactory $phpDocInfoFactory;

/**
* @readonly
*/
private BetterNodeFinder $betterNodeFinder;

public function __construct(
NodeNameResolver $nodeNameResolver,
PhpDocInfoFactory $phpDocInfoFactory,
BetterNodeFinder $betterNodeFinder
) {
$this->nodeNameResolver = $nodeNameResolver;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->betterNodeFinder = $betterNodeFinder;
}

public function inferParam(Param $param): Type
{
$functionLike = $this->resolveScopeNode($param);
if (! $functionLike instanceof FunctionLike) {
return new MixedType();
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike);
$paramTypesByName = $phpDocInfo->getParamTypesByName();
if ([] === $paramTypesByName) {
return new MixedType();
}
return $this->matchParamNodeFromDoc($paramTypesByName, $param);
}

/**
* @return ClassMethod|Function_|null
*/
private function resolveScopeNode(Param $param): ?Node
{
return $this->betterNodeFinder->findParentByTypes($param, [ClassMethod::class, Function_::class]);
}

/**
* @param Type[] $paramWithTypes
*/
private function matchParamNodeFromDoc(array $paramWithTypes, Param $param): Type
{
$paramNodeName = '$' . $this->nodeNameResolver->getName($param->var);
return $paramWithTypes[$paramNodeName] ?? new MixedType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ class MySolrIndexer
$document->setMultiValue('key', 'foo', true);
}

/**
* @param Apache_Solr_Document[] $documents
*/
public function multiple(array $documents)
{
/** @var Apache_Solr_Document $document */
Expand Down Expand Up @@ -48,9 +45,6 @@ class MySolrIndexer
$document->addField('key', 'foo', true);
}

/**
* @param Document[] $documents
*/
public function multiple(array $documents)
{
/** @var Apache_Solr_Document $document */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use Nimut\TestingFramework\TestCase\UnitTestCase;

class MyUnitTest extends UnitTestCase
{
/**
* @var AccessibleMockObjectInterface
*/
protected $fooBarBaz;
protected AccessibleMockObjectInterface $fooBarBaz;

public function testFooBar()
{
Expand All @@ -35,10 +32,7 @@ use TYPO3\TestingFramework\Core\Exception;

class MyUnitTest extends UnitTestCase
{
/**
* @var AccessibleObjectInterface
*/
protected $fooBarBaz;
protected AccessibleObjectInterface $fooBarBaz;

public function testFooBar()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
use Ssch\TYPO3Rector\Set\Extension\NimutTestingFrameworkSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->disableImportNames();
$rectorConfig->importNames(false);
$rectorConfig->sets([NimutTestingFrameworkSetList::NIMUT_TESTING_FRAMEWORK_TO_TYPO3_TESTING_FRAMEWORK]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final class ContentObjectRendererFileResourceRectorTest extends AbstractRectorTe
public function test(string $filePath): void
{
$this->markTestIncomplete('The comparison is false positive wrongly.');
#$this->doTestFile($filePath);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../config/config_test.php');
$rectorConfig->disableImportNames();
$rectorConfig->importNames(false);
$rectorConfig->rule(RefactorTypeInternalTypeFileAndFileReferenceToFalRector::class);
};