ParentType   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 26
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildModel() 0 3 3
A getSchema() 0 7 2
A getRelatedModel() 0 3 1
A getPivot() 0 3 3
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