mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
fix: wrap bare intersection types in parentheses when adding nullable (#1756)
When a MorphTo relation's docblock uses a bare intersection type in the generic parameter (e.g. `MorphTo<BaseModel&CanBeAssigned, $this>`), the generated property type incorrectly becomes `BaseModel&CanBeAssigned|null` instead of the correct `(BaseModel&CanBeAssigned)|null`. This adds `wrapIntersectionType()` which ensures bare intersection types are wrapped in parentheses before `|null` is appended, producing valid DNF type syntax. Applied in both `setProperty()` and `applyNullability()`.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MorphToIntersection;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||
|
||||
class Test extends AbstractModelsCommand
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$command = $this->app->make(ModelsCommand::class);
|
||||
|
||||
$tester = $this->runCommand($command, [
|
||||
'--write' => true,
|
||||
]);
|
||||
|
||||
$this->assertSame(0, $tester->getStatusCode());
|
||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||
$this->assertMatchesMockedSnapshot();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user