Skip to content

Commit

Permalink
Make NameScopeFactory simpler (#6092)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Jun 30, 2024
1 parent b94486c commit ef33350
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\DependencyInjection;

use Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\Rules\English\InflectorFactory;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -152,6 +151,7 @@
use Rector\PHPStanStaticTypeMapper\TypeMapper\ParentStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ResourceTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\SelfObjectTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StrictMixedTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper;
Expand Down
18 changes: 5 additions & 13 deletions src/StaticTypeMapper/Naming/NameScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,13 @@ public function createNameScopeFromNodeWithoutTemplateTypes(Node $node): NameSco
return new NameScope($namespace, $usesAliasesToNames, $className);
}

/**
* @api
* @deprecated Use createNameScopeFromNodeWithoutTemplateTypes() instead, as same
*/
public function createNameScopeFromNode(Node $node): NameScope
{
$nameScope = $this->createNameScopeFromNodeWithoutTemplateTypes($node);

/** @var non-empty-string|null $namespace */
$namespace = $nameScope->getNamespace();

return new NameScope(
$namespace,
$nameScope->getUses(),
$nameScope->getClassName(),
null,
null
// $templateTypeMap
);
return $this->createNameScopeFromNodeWithoutTemplateTypes($node);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/StaticTypeMapper/StaticTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function mapPHPStanPhpDocTypeToPHPStanType(PhpDocTagValueNode $phpDocTagV

public function mapPHPStanPhpDocTypeNodeToPHPStanType(TypeNode $typeNode, Node $node): Type
{
$nameScope = $this->nameScopeFactory->createNameScopeFromNode($node);
$nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($node);
return $this->phpDocTypeMapper->mapToPHPStanType($typeNode, $node, $nameScope);
}
}
2 changes: 1 addition & 1 deletion tests/StaticTypeMapper/PhpDoc/PhpDocTypeMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void
public function test(TypeNode $typeNode, string $expectedPHPStanType): void
{
$nop = new Nop();
$nameScope = $this->nameScopeFactory->createNameScopeFromNode($nop);
$nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($nop);

$phpStanType = $this->phpDocTypeMapper->mapToPHPStanType($typeNode, $nop, $nameScope);
$this->assertInstanceOf($expectedPHPStanType, $phpStanType);
Expand Down

0 comments on commit ef33350

Please sign in to comment.