ParentType::getPivot()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 1
c 0
b 0
f 0
nc 4
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 ParentType extends SingleType
8
{
9
    protected $isParent = true;
10
    
11
    public function getSchema()
12
    {
13
        $schema = "";
14
        $parentTable = $this->hasSelfParent() ? $this->getParentModule() : $this->typeOption;
15
        $schema .= "\$table->bigInteger('".$this->getForeignKey()."')->unsigned()->nullable();".PHP_EOL.$this->getTabs(3);
16
        $schema .= "\$table->foreign('".$this->getForeignKey()."')->references('id')->on('$parentTable')->onDelete('set null');".PHP_EOL;
17
        return $schema;
18
    }
19
20
    public function getPivot()
21
    {
22
        return ($this->typeOption == $this->getParentModule() || $this->typeOption == "self") ? $this->getParentModel() : ucfirst(Str::singular(Str::camel($this->typeOption)));
23
    }
24
25
    public function getRelatedModel()
26
    {
27
        return $this->getChildModel();
28
    }
29
    
30
    public function getChildModel()
31
    {
32
        return ($this->typeOption == $this->getParentModule() || $this->typeOption == "self") ? $this->getParentModel() : ucfirst(Str::singular(Str::camel($this->typeOption)));
33
    }
34
}
35