From bc158a1b86147d351f948041071a6b688c8f51f8 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 8 Feb 2024 12:09:30 +0200 Subject: [PATCH] Add `AllowDynamicProperties` Attribute to cooperate with php8.2 deprecation (#1428) * Add `AllowDynamicProperties` Attribute to cooperate with php8.2 deprecation * lint snapshot --- src/Console/ModelsCommand.php | 6 ++++-- .../GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index e99848b..343440e 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1081,9 +1081,11 @@ class ModelsCommand extends Command } $classname = $this->write_mixin ? $mixinClassName : $classname; - $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} "; - if (!$this->write_mixin) { + $allowDynamicAttributes = $this->write_mixin ? "#[\AllowDynamicProperties]\n\t" : ''; + $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}{$allowDynamicAttributes}class {$classname} "; + + if (! $this->write_mixin) { $output .= "extends \Eloquent "; if ($interfaceNames) { diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php index 71dab45..c290996 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php @@ -184,6 +184,7 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value) * @mixin \Eloquent */ + #[\AllowDynamicProperties] class IdeHelperPost {} }