Passed
Push — master ( 4e0c2f...af0465 )
by Prateek
04:42 queued 02:26
created

Model::getMassAssignables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Prateekkarki\Laragen\Generators\Common;
3
4
use Prateekkarki\Laragen\Generators\BaseGenerator;
5
use Prateekkarki\Laragen\Generators\GeneratorInterface;
6
7
class Model extends BaseGenerator implements GeneratorInterface
8
{
9
    public function generate()
10
    {
11
        $modelTemplate = $this->buildTemplate('Model', [
12
            '{{modelName}}'       => $this->module->getModelName(),
13
            '{{massAssignables}}' => $this->getMassAssignables(),
14
            '{{foreignMethods}}'  => $this->getForeignMethods()
15
        ]);
16
        
17
        $fullFilePath = $this->getPath("app/Models/").$this->module->getModelName().".php";
18
        file_put_contents($fullFilePath, $modelTemplate);
19
        return $fullFilePath;
20
    }
21
22
    protected function getMassAssignables()
23
    {
24
        return "'".implode("', '", $this->module->getNativeColumns())."'";
25
    }
26
27
    protected function getForeignMethods()
28
    {
29
        $foreignMethods = "";
30
31
        foreach ($this->module->getForeignColumns('parent') as $parents) {
32
            foreach ($parents as $column => $parent) {
33
                $foreignMethods .= $this->buildTemplate('Model-parent', [
34
                    '{{parent}}'      => str_singular($parent),
0 ignored issues
show
Deprecated Code introduced by
The function str_singular() has been deprecated: Str::singular() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

34
                    '{{parent}}'      => /** @scrutinizer ignore-deprecated */ str_singular($parent),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
35
                    '{{columnName}}'  => str_singular($column),
0 ignored issues
show
Deprecated Code introduced by
The function str_singular() has been deprecated: Str::singular() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

35
                    '{{columnName}}'  => /** @scrutinizer ignore-deprecated */ str_singular($column),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
36
                    '{{parentModel}}' => ($parent == 'users' && class_exists('\\App\\User')) ? "\\App\\User" : ucfirst(camel_case(str_singular($parent)))
0 ignored issues
show
Deprecated Code introduced by
The function camel_case() has been deprecated: Str::camel() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

36
                    '{{parentModel}}' => ($parent == 'users' && class_exists('\\App\\User')) ? "\\App\\User" : ucfirst(/** @scrutinizer ignore-deprecated */ camel_case(str_singular($parent)))

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_singular() has been deprecated: Str::singular() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

36
                    '{{parentModel}}' => ($parent == 'users' && class_exists('\\App\\User')) ? "\\App\\User" : ucfirst(camel_case(/** @scrutinizer ignore-deprecated */ str_singular($parent)))

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
37
                ]);
38
            }
39
        }
40
41
        return $foreignMethods;
42
    }
43
}
44