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:
Pieter Willekens
2026-02-10 15:19:29 +01:00
committed by GitHub
parent 5aca186d92
commit 3bd70eafd0
6 changed files with 141 additions and 2 deletions
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MorphToIntersection\Models;
interface CanBeAssigned
{
}