Skip to content
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
2 changes: 2 additions & 0 deletions packages/node-type-resolver/src/PhpDoc/PhpDocTypeRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\Ast\PhpDocNodeTraverser;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\StaticTypeMapper;

Expand All @@ -36,6 +37,7 @@ public function __construct(PhpDocNodeTraverser $phpDocNodeTraverser, StaticType
*/
public function changeUnderscoreType(Node $node, string $namespacePrefix, array $excludedClasses): void
{
/** @var PhpDocInfo|null $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
if ($phpDocInfo === null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
Expand Down Expand Up @@ -64,7 +64,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
return new Identifier('array');
return new Name('array');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\BooleanType;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('bool');
return new Name('bool');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\CallableType;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('callable');
return new Name('callable');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Closure;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ClosureType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -37,7 +37,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('callable');
return new Name('callable');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\FloatType;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('float');
return new Name('float');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\IntegerType;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('int');
return new Name('int');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
return new Identifier('iterable');
return new Name('iterable');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
if ($type instanceof SelfObjectType) {
return new Identifier('self');
return new Name('self');
}

if ($type instanceof ShortenedObjectType) {
Expand All @@ -66,7 +65,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
}

if ($type instanceof GenericObjectType && $type->getClassName() === 'object') {
return new Identifier('object');
return new Name('object');
}

// fallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ObjectWithoutClassType;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('object');
return new Name('object');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -33,7 +33,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
return new Identifier('parent');
return new Name('parent');
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -33,7 +33,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
return new Identifier('self');
return new Name('self');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\StaticType;
use PHPStan\Type\ThisType;
Expand Down Expand Up @@ -49,10 +49,10 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
if ($type instanceof ThisType) {
// @todo wait for PHPStan to differentiate between self/static
if ($this->phpVersionProvider->isAtLeast(PhpVersionFeature::STATIC_RETURN_TYPE)) {
return new Identifier('static');
return new Name('static');
}

return new Identifier('self');
return new Name('self');
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ThisType;
Expand Down Expand Up @@ -33,7 +33,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode
*/
public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
{
return new Identifier('self');
return new Name('self');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier('string');
return new Name('string');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ private function shouldSkipIterable(UnionType $unionType): bool
return $unionTypeAnalysis->hasIterable() && $unionTypeAnalysis->hasArray();
}

private function matchArrayTypes(UnionType $unionType): ?Identifier
/**
* @return Name|NullableType|null
*/
private function matchArrayTypes(UnionType $unionType): ?Node
{
$unionTypeAnalysis = $this->unionTypeAnalyzer->analyseForNullableAndIterable($unionType);
if ($unionTypeAnalysis === null) {
Expand All @@ -162,10 +165,10 @@ private function matchArrayTypes(UnionType $unionType): ?Identifier

$type = $unionTypeAnalysis->hasIterable() ? 'iterable' : 'array';
if ($unionTypeAnalysis->isNullableType()) {
return new Identifier('?' . $type);
return new NullableType($type);
}

return new Identifier($type);
return new Name($type);
}

private function matchTypeForNullableUnionType(UnionType $unionType): ?Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;

use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node
return null;
}

return new Identifier(self::VOID);
return new Name(self::VOID);
}

public function mapToDocString(Type $type, ?Type $parentType = null): string
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ parameters:
- utils

excludes_analyse:
# phsptan bug
- utils/phpstan-extensions/src/Rule/PreventParentMethodVisibilityOverrideRule.php
- utils/phpstan-extensions/src/Rule/KeepRectorNamespaceForRectorRule.php

# generated files
- 'packages/doctrine-annotation-generated/src/ConstantPreservingDocParser.php'
- 'packages/doctrine-annotation-generated/src/ConstantPreservingAnnotationReader.php'
Expand Down
2 changes: 1 addition & 1 deletion rules/psr4/src/Composer/PSR4AutoloadPathsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class PSR4AutoloadPathsProvider
private $cachedComposerJsonPSR4AutoloadPaths = [];

/**
* @return string[]
* @return string[]|string[][]
*/
public function provide(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ private function getExpectedNamespace(Node $node): ?string

foreach ($psr4Autoloads as $namespace => $path) {
// remove extra slash
$path = rtrim($path, '/');
/** @var string[] $paths */
$paths = is_array($path) ? $path : [$path];

if (Strings::startsWith($smartFileInfo->getRelativeDirectoryPath(), $path)) {
$expectedNamespace = $namespace . $this->resolveExtraNamespace($smartFileInfo, $path);
foreach ($paths as $path) {
$path = rtrim($path, '/');

return rtrim($expectedNamespace, '\\');
if (Strings::startsWith($smartFileInfo->getRelativeDirectoryPath(), $path)) {
$expectedNamespace = $namespace . $this->resolveExtraNamespace($smartFileInfo, $path);

return rtrim($expectedNamespace, '\\');
}
}
}

Expand Down