MultipleType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 25
c 1
b 0
f 0
dl 0
loc 55
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelatedModel() 0 3 1
A getMigrationPivot() 0 3 1
A getPivotTable() 0 3 1
A getPivotSchema() 0 10 1
A getPivotColumns() 0 7 2
A getTypeColumns() 0 3 1
A getPivot() 0 3 1
1
<?php
2
namespace Prateekkarki\Laragen\Models\Types\File;
3
use Prateekkarki\Laragen\Models\TypeResolver;
4
use Prateekkarki\Laragen\Models\Types\FileType;
5
use Illuminate\Support\Str;
6
7
class MultipleType extends FileType
8
{
9
    protected $hasModel = true;
10
    protected $isRelational = true;
11
    protected $hasMultipleFiles = true;
12
    protected $formType = 'multipleFiles';
13
    protected $stubs = [
14
        'modelMethod' => 'common/Models/fragments/belongsTo',
15
        'foreignMethod' => 'common/Models/fragments/hasMany'
16
    ];
17
18
    public function getPivotSchema()
19
    {
20
        $modelName = $this->getParentModelLowercase();
21
        $moduleName = $this->getParentModule();
22
        $schema = '$table->bigInteger("'.$modelName.'_id")->unsigned()->nullable();'.PHP_EOL.$this->getTabs(3);
23
        $schema .= "\$table->foreign('".$modelName."_id')->references('id')->on('".$moduleName."')->onDelete('set null');".PHP_EOL.$this->getTabs(3);
24
        $schema .= '$table->string("filename", 192);'.PHP_EOL.$this->getTabs(3);
25
        $schema .= '$table->integer("size");'.PHP_EOL.$this->getTabs(3);
26
        $schema .= '$table->timestamps();'.PHP_EOL.$this->getTabs(3);
27
        return $schema;
28
    }
29
30
    public function getPivotTable()
31
    {
32
        return $this->getParentModelLowercase()."_".strtolower(Str::plural($this->columnName));
33
    }
34
35
    public function getMigrationPivot()
36
    {
37
        return $this->getParentModel().Str::plural($this->getChildModel());
38
    }
39
40
    public function getRelatedModel()
41
    {
42
        return $this->getPivot();
43
    }
44
45
    public function getPivot()
46
    {
47
        return $this->getParentModel().$this->getChildModel();
48
    }
49
50
    public function getPivotColumns()
51
    {
52
        $columnModels = [];
53
        foreach ($this->getLaragenColumns() as $column => $optionString) {
0 ignored issues
show
Bug introduced by
The method getLaragenColumns() does not exist on Prateekkarki\Laragen\Mod...Types\File\MultipleType. 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

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