Repository: laravel-shift/blueprint (php)

Issue:
Morphs php annotation incorrect
* Laravel Version: 8.24.0
* PHP Version: 8.0
* Blueprint Version: 1.20.2
* Platform: Mac

In yaml
```yaml
obj: morphs
```

Generated annotation in Model:
```php
/**
 * @property string $obj
 */
```

Expected:
```php
/**
 * @property int $obj_id
 * @property string $obj_type
 */
```

Didn't test morphsUuid...


Pull request:
Add additional phpdocs annotation
Supersedes: #423

- Morphs 
- uuidMorphs 
- nullableMorphs 
- nullableUuidMorphs

close #422 
close #423

Patch:
diff --git a/src/Generators/ModelGenerator.php b/src/Generators/ModelGenerator.php
index 12beb68..01925e3 100644
--- a/src/Generators/ModelGenerator.php
+++ b/src/Generators/ModelGenerator.php
@@ -91,8 +91,30 @@ class ModelGenerator implements Generator
         $phpDoc .= PHP_EOL;
         /** @var Column $column */
         foreach ($model->columns() as $column) {
-            $phpDoc .= sprintf(' * @property %s $%s', $this->phpDataType($column->dataType()), $column->name());
-            $phpDoc .= PHP_EOL;
+            if ($column->dataType() === 'morphs') {
+                $phpDoc .= ' * @property int $'. $column->name() . '_id';
+                $phpDoc .= PHP_EOL;
+                $phpDoc .= ' * @property string $'. $column->name() . '_type';
+                $phpDoc .= PHP_EOL;
+            } elseif ($column->dataType() === 'nullableMorphs') {
+                $phpDoc .= ' * @property int|null $'. $column->name() . '_id';
+                $phpDoc .= PHP_EOL;
+                $phpDoc .= ' * @property string|null $'. $column->name() . '_type';
+                $phpDoc .= PHP_EOL;
+            } elseif ($column->dataType() === 'uuidMorphs') {
+                $phpDoc .= ' * @property string $'. $column->name() . '_id';
+                $phpDoc .= PHP_EOL;
+                $phpDoc .= ' * @property string $'. $column->name() . '_type';
+                $phpDoc .= PHP_EOL;
+            } elseif ($column->dataType() === 'nullableUuidMorphs') {
+                $phpDoc .= ' * @property string|null $'. $column->name() . '_id';
+                $phpDoc .= PHP_EOL;
+                $phpDoc .= ' * @property string|null $'. $column->name() . '_type';
+                $phpDoc .= PHP_EOL;
+            } else {
+                $phpDoc .= sprintf(' * @property %s $%s', $this->phpDataType($column->dataType()), $column->name());
+                $phpDoc .= PHP_EOL;
+            }
         }
 
         if ($model->usesSoftDeletes()) {


Test patch:
diff --git a/tests/Feature/Generators/ModelGeneratorTest.php b/tests/Feature/Generators/ModelGeneratorTest.php
index 6c64a12..04107bd 100644
--- a/tests/Feature/Generators/ModelGeneratorTest.php
+++ b/tests/Feature/Generators/ModelGeneratorTest.php
@@ -676,6 +676,7 @@ class ModelGeneratorTest extends TestCase
             ['drafts/relationships.yaml', 'app/Comment.php', 'models/relationships-phpdoc.php'],
             ['drafts/disable-auto-columns.yaml', 'app/State.php', 'models/disable-auto-columns-phpdoc.php'],
             ['drafts/foreign-key-shorthand.yaml', 'app/Comment.php', 'models/foreign-key-shorthand-phpdoc.php'],
+            ['drafts/optimize.yaml', 'app/Optimize.php', 'models/optimize.php'],
         ];
     }
 
diff --git a/tests/fixtures/drafts/optimize.yaml b/tests/fixtures/drafts/optimize.yaml
index 9c83cb0..3bd6e05 100644
--- a/tests/fixtures/drafts/optimize.yaml
+++ b/tests/fixtures/drafts/optimize.yaml
@@ -6,6 +6,9 @@ models:
     int: integer unsigned
     dec: decimal:8,2 unsigned
     big: bigInteger unsigned
-    foo: morphs nullable
-    foobar: uuidMorphs nullable
-    timestamps: false
+    foo: morphs
+    bar: uuidMorphs nullable
+    baz: nullableMorphs
+    foobar: uuidMorphs
+    foobarbaz: nullableUuidMorphs
+    timestamps: true
\ No newline at end of file
diff --git a/tests/fixtures/migrations/optimize.php b/tests/fixtures/migrations/optimize.php
index 43864c5..80f1c98 100644
--- a/tests/fixtures/migrations/optimize.php
+++ b/tests/fixtures/migrations/optimize.php
@@ -21,8 +21,12 @@ class CreateOptimizesTable extends Migration
             $table->unsignedInteger('int');
             $table->unsignedDecimal('dec', 8, 2);
             $table->unsignedBigInteger('big');
-            $table->nullableMorphs('foo');
-            $table->nullableUuidMorphs('foobar');
+            $table->morphs('foo');
+            $table->nullableUuidMorphs('bar');
+            $table->nullableMorphs('baz');
+            $table->uuidMorphs('foobar');
+            $table->nullableUuidMorphs('foobarbaz');
+            $table->timestamps();
         });
     }
 
diff --git a/tests/fixtures/models/optimize.php b/tests/fixtures/models/optimize.php
new file mode 100644
index 0000000..a7844d8
--- /dev/null
+++ b/tests/fixtures/models/optimize.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * @property int $id
+ * @property int $tiny
+ * @property int $small
+ * @property int $medium
+ * @property int $int
+ * @property float $dec
+ * @property int $big
+ * @property int $foo_id
+ * @property string $foo_type
+ * @property string $bar_id
+ * @property string $bar_type
+ * @property int|null $baz_id
+ * @property string|null $baz_type
+ * @property string $foobar_id
+ * @property string $foobar_type
+ * @property string|null $foobarbaz_id
+ * @property string|null $foobarbaz_type
+ * @property \Carbon\Carbon $created_at
+ * @property \Carbon\Carbon $updated_at
+ */
+class Optimize extends Model
+{
+    /**
+     * The attributes that are mass assignable.
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'tiny',
+        'small',
+        'medium',
+        'int',
+        'dec',
+        'big',
+        'foo',
+        'bar',
+        'baz',
+        'foobar',
+        'foobarbaz',
+    ];
+
+    /**
+     * The attributes that should be cast to native types.
+     *
+     * @var array
+     */
+    protected $casts = [
+        'id' => 'integer',
+        'tiny' => 'integer',
+        'small' => 'integer',
+        'medium' => 'integer',
+        'dec' => 'decimal:2',
+        'big' => 'integer',
+    ];
+}