Passed
Branch master (d88b3b)
by Prateek
03:56
created

OptionType::getTypeColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
namespace Prateekkarki\Laragen\Models\Types\Relational\Single;
3
4
use Prateekkarki\Laragen\Models\Types\Relational\SingleType;
5
use Illuminate\Support\Str;
6
7
class OptionType extends SingleType
8
{
9
    protected $needsTableInit = true;
10
    protected $hasOptions = true;
11
12
    public function getSchema()
13
    {
14
        $schema = "";
15
        $schema .= "\$table->bigInteger('".$this->getForeignKey()."')->unsigned()->nullable();".PHP_EOL.$this->getTabs(3);
16
        $schema .= "\$table->foreign('".$this->getForeignKey()."')->references('id')->on('".$this->getPivotTable()."')->onDelete('set null');".PHP_EOL;
17
        return $schema;
18
    }
19
20
    public function getDbData()
21
    {
22
        return explode(':',$this->optionArray[0]);
23
    }
24
25
    public function getPivotSchema()
26
    {
27
        $schema = '$table->string("title", 192);'.PHP_EOL.$this->getTabs(3);
28
        $schema .= '$table->timestamps();'.PHP_EOL.$this->getTabs(3);
29
        return $schema;
30
    }
31
    
32
    public function getRelatedModel()
33
    {
34
        return $this->getPivot();
35
    }
36
    
37
    public function getPivotTable()
38
    {
39
        return $this->getParentModelLowercase() . "_" . Str::plural($this->columnName);
40
    }
41
42
    public function getMigrationPivot()
43
    {
44
        return $this->getParentModel() . Str::plural($this->getChildModel());
45
    }
46
47
    public function getPivot()
48
    {
49
        return $this->getParentModel() . $this->getChildModel();
50
    }
51
    
52
    public function getTypeColumns()
53
    {
54
        return [$this->getParentModelLowercase().'_id', 'title'];
55
    }
56
}
57