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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\Annotation\AnnotationNaming;
Expand Down Expand Up @@ -245,6 +247,15 @@ public function changeVarTag(Node $node, Type $newType): void
return;
}

// prevent existing type override by mixed
if (! $currentVarType instanceof MixedType) {
if ($newType instanceof ConstantArrayType) {
if ($newType->getItemType() instanceof NeverType) {
return;
}
}
}

$this->removeTagFromNode($node, 'var', true);
$this->addTypeSpecificTag($node, 'var', $newType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function provideDataForTest(): Iterator
yield [__DIR__ . '/Fixture/typed_array.php.inc'];
yield [__DIR__ . '/Fixture/typed_array_nested.php.inc'];
yield [__DIR__ . '/Fixture/symfony_console_command.php.inc'];
yield [__DIR__ . '/Fixture/skip_more_specific.php.inc'];
}

protected function getRectorClass(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rector\TypeDeclaration\Tests\Rector\Property\CompleteVarDocTypePropertyRector\Fixture;

use Rector\TypeDeclaration\Tests\Rector\Property\CompleteVarDocTypePropertyRector\Source\SomeService;

class SkipMoreSpecific
{
/**
* @var SomeService[]
*/
private static $registry = [];
/**
* register an SomeService for using.
*
* @param SomeService $service
*/
public static function register(SomeService $service)
{
self::$registry[$service->getLabel()] = $service;
}
/**
* find registered SomeService.
*
* @return SomeService[]
*/
public static function getRegisteredSomeServices()
{
return self::$registry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Rector\TypeDeclaration\Tests\Rector\Property\CompleteVarDocTypePropertyRector\Source;

final class SomeService
{

}