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
16 changes: 9 additions & 7 deletions rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public function narrowToFullyQualifiedOrAliasedObjectType(

$uses = $this->useImportsResolver->resolve();

$aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses);
if ($aliasedObjectType instanceof AliasedObjectType) {
return $aliasedObjectType;
}
if (! $withPreslash) {
$aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses);
if ($aliasedObjectType instanceof AliasedObjectType) {
return $aliasedObjectType;
}

$shortenedObjectType = $this->matchShortenedObjectType($objectType, $uses);
if ($shortenedObjectType !== null) {
return $shortenedObjectType;
$shortenedObjectType = $this->matchShortenedObjectType($objectType, $uses);
if ($shortenedObjectType !== null) {
return $shortenedObjectType;
}
}

if ($this->reflectionProvider->hasClass($className)) {
Expand Down
12 changes: 12 additions & 0 deletions stubs/Carbon/CarbonInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Carbon;

if (interface_exists('Carbon\CarbonInterface')) {
return;
}

interface CarbonInterface
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Carbon\Carbon;
use Carbon\CarbonInterface;

/**
* @property \Carbon\CarbonInterface|null $deleted_at
*/
class InUseFqcnDocblock
{
/**
* @return CarbonInterface[]
*/
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Carbon\Carbon;
use Carbon\CarbonInterface;

/**
* @property CarbonInterface|null $deleted_at
*/
class InUseFqcnDocblock
{
/**
* @return CarbonInterface[]
*/
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Illuminate\Support\Carbon;
use Carbon\CarbonInterface;

/**
* @property \Carbon\CarbonInterface|null $deleted_at
*/
class NotInUseFqcnDocblock
{
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Illuminate\Support\Carbon;
use Carbon\CarbonInterface;

/**
* @property CarbonInterface|null $deleted_at
*/
class NotInUseFqcnDocblock
{
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missing .php.inc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Carbon\Carbon;
use Carbon\CarbonInterface;

/**
* @property \Carbon\CarbonInterface|null $deleted_at
*/
class NotInUseFqcnDocblock2
{
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\NamespacedUseAutoImport\Fixture;

use Carbon\Carbon;

/**
* @property CarbonInterface|null $deleted_at
*/
class NotInUseFqcnDocblock2
{
public function demoFunction(): array
{
return [Carbon::parse('2026-01-01 11:16:01')];
}
}

?>
Loading