MultipleDataType::getRelatedModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace Prateekkarki\Laragen\Models\Types\Relational\Multiple;
3
use Prateekkarki\Laragen\Models\TypeResolver;
4
use Prateekkarki\Laragen\Models\Types\Relational\MultipleType;
5
use Illuminate\Support\Str;
6
7
class MultipleDataType extends MultipleType
8
{
9
    protected $hasModel = true;
10
    protected $isMultipleType = true;
11
    protected $formType = 'multiple';
12
    protected $stubs = [
13
        'modelMethod' => 'common/Models/fragments/belongsTo',
14
        'foreignMethod' => 'common/Models/fragments/hasMany'
15
    ];
16
17
    public function getPivotSchema()
18
    {
19
        $schema = PHP_EOL.$this->getTabs(3);
20
        foreach ($this->getPivotColumns() as $type) {
21
            $schema .= $type->getSchema().PHP_EOL.$this->getTabs(3);
22
        }
23
        $schema .= '$table->timestamps();'.PHP_EOL.$this->getTabs(3);
24
        return $schema;
25
    }
26
27
    public function getRelatedModel()
28
    {
29
        return $this->getPivot();
30
    }
31
32
    public function getDisplay()
33
    {
34
        return strtolower(Str::singular(str_replace("_", " ", $this->columnName)));
35
    }
36
37
    public function getPivot()
38
    {
39
        return $this->getParentModel().$this->getChildModel();
40
    }
41
42
    public function getMigrationPivot()
43
    {
44
        return $this->getParentModel().Str::plural($this->getChildModel());
45
    }
46
47
    public function getPivotTable()
48
    {
49
        return $this->getParentModelLowercase()."_".strtolower(Str::plural($this->columnName));
50
    }
51
52
    public function getPivotColumns()
53
    {
54
        $columns = [];
55
        foreach ($this->getLaragenColumns() as $column => $optionString) {
0 ignored issues
show
Bug introduced by
The method getLaragenColumns() does not exist on Prateekkarki\Laragen\Mod...ltiple\MultipleDataType. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        foreach ($this->/** @scrutinizer ignore-call */ getLaragenColumns() as $column => $optionString) {
Loading history...
56
            $columns[$column] = TypeResolver::getType($this->getPivotTable(), $column, $optionString);
57
        }
58
        return $columns;
59
    }
60
61
    public function getTypeColumns()
62
    {
63
        return [$this->columnName, $this->getParentModelLowercase().'_id'];
64
    }
65
}
66