• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-entity-generator / 21236534569

22 Jan 2026 04:53AM UTC coverage: 99.713% (-0.3%) from 100.0%
21236534569

Pull #241

github

web-flow
Merge 06991d18c into 962b971b7
Pull Request #241: [239]: append field modifiers instead of uppercase options

161 of 164 new or added lines in 17 files covered. (98.17%)

1 existing line in 1 file now uncovered.

1043 of 1046 relevant lines covered (99.71%)

11.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.14
/src/Generators/MigrationGenerator.php
1
<?php
2

3
namespace RonasIT\Support\Generators;
4

5
use Carbon\Carbon;
6
use RonasIT\Support\Collections\FieldsCollection;
7
use RonasIT\Support\Enums\FieldModifierEnum;
8
use RonasIT\Support\Enums\FieldTypeEnum;
9
use RonasIT\Support\Events\SuccessCreateMessage;
10
use RonasIT\Support\ValueObjects\Field;
11

12
class MigrationGenerator extends EntityGenerator
13
{
14
    public function generate(): void
15
    {
16
        if (!$this->isStubExists('migration')) {
6✔
17
            return;
1✔
18
        }
19

20
        $entities = $this->getTableName($this->model);
5✔
21

22
        $content = $this->getStub('migration', [
5✔
23
            'class' => $this->getPluralName($this->model),
5✔
24
            'entity' => $this->model,
5✔
25
            'entities' => $entities,
5✔
26
            'relations' => $this->prepareRelations(),
5✔
27
            'fields' => $this->fields,
5✔
28
            'table' => $this->generateTable($this->fields),
5✔
29
        ]);
5✔
30

31
        $now = Carbon::now()->format('Y_m_d_His');
5✔
32

33
        $this->saveClass('migrations', "{$now}_{$entities}_create_table", $content);
5✔
34

35
        event(new SuccessCreateMessage("Created a new Migration: {$entities}_create_table"));
5✔
36
    }
37

38
    protected function isJson(FieldTypeEnum $type): bool
39
    {
40
        return $type === FieldTypeEnum::Json;
2✔
41
    }
42

43
    protected function isRequired(array $modifiers): bool
44
    {
45
        return in_array(FieldModifierEnum::Required, $modifiers);
2✔
46
    }
47

48
    protected function isNullable(array $modifiers): bool
49
    {
50
        return empty($modifiers);
2✔
51
    }
52

53
    protected function getJsonLine(string $fieldName): string
54
    {
55
        if (env('DB_CONNECTION') == 'mysql') {
2✔
56
            return "\$table->json('{$fieldName}')->nullable();";
1✔
57
        }
58

59
        return "\$table->jsonb('{$fieldName}')->default(\"{}\");";
1✔
60
    }
61

62
    protected function getRequiredLine(string $fieldName, string $typeName): string
63
    {
64
        if ($typeName === 'timestamp' && env('DB_CONNECTION') === 'mysql') {
2✔
65
            return "\$table->{$typeName}('{$fieldName}')->nullable();";
1✔
66
        }
67

68
        return "\$table->{$typeName}('{$fieldName}');";
2✔
69
    }
70

71
    protected function getNonRequiredLine(string $fieldName, string $typeName): string
72
    {
73
        return "\$table->{$typeName}('{$fieldName}')->nullable();";
2✔
74
    }
75

76
    protected function generateTable(FieldsCollection $fields): array
77
    {
78
        $resultTable = [];
5✔
79

80
        foreach ($fields as $field) {
5✔
81
            $resultTable[] = $this->getTableRow($field->type, $field);
2✔
82
        }
83

84
        return $resultTable;
5✔
85
    }
86

87
    protected function getTableRow(FieldTypeEnum $fieldType, Field $field): string
88
    {
89
        if ($this->isJson($fieldType)) {
2✔
90
            return $this->getJsonLine($field->name);
2✔
91
        }
92

93
        if ($this->isRequired($field->modifiers)) {
2✔
94
            return $this->getRequiredLine($field->name, $fieldType->value);
2✔
95
        }
96

97
        if ($this->isNullable($field->modifiers)) {
2✔
98
            return $this->getNonRequiredLine($field->name, $fieldType->value);
2✔
99
        }
100

NEW
UNCOV
101
        return '';
×
102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc