GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ModelGenerator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootNamespace() 0 4 1
A getPathConfigNode() 0 4 1
A getPath() 0 4 1
A getBasePath() 0 4 1
A getReplacements() 0 7 1
A getFillable() 0 13 3
A getSchemaParser() 0 4 1
1
<?php
2
3
namespace Milkmeowo\Framework\Repository\Generators;
4
5
use Milkmeowo\Framework\Repository\Generators\Migrations\SchemaParser;
6
7
class ModelGenerator extends Generator
8
{
9
    /**
10
     * Get stub name.
11
     *
12
     * @var string
13
     */
14
    protected $stub = 'model';
15
16
    /**
17
     * Get root namespace.
18
     *
19
     * @return string
20
     */
21
    public function getRootNamespace()
22
    {
23
        return parent::getRootNamespace().parent::getConfigGeneratorClassPath($this->getPathConfigNode());
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConfigGeneratorClassPath() instead of getRootNamespace()). Are you sure this is correct? If so, you might want to change this to $this->getConfigGeneratorClassPath().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
24
    }
25
26
    /**
27
     * Get generator path config node.
28
     *
29
     * @return string
30
     */
31
    public function getPathConfigNode()
32
    {
33
        return 'models';
34
    }
35
36
    /**
37
     * Get destination path for generated file.
38
     *
39
     * @return string
40
     */
41
    public function getPath()
42
    {
43
        return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true).'/'.$this->getName().'.php';
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConfigGeneratorClassPath() instead of getPath()). Are you sure this is correct? If so, you might want to change this to $this->getConfigGeneratorClassPath().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
44
    }
45
46
    /**
47
     * Get base path of destination file.
48
     *
49
     * @return string
50
     */
51
    public function getBasePath()
52
    {
53
        return config('repository.generator.basePath', app()->path());
54
    }
55
56
    /**
57
     * Get array replacements.
58
     *
59
     * @return array
60
     */
61
    public function getReplacements()
62
    {
63
        return array_merge(parent::getReplacements(), [
64
            'fillable' => $this->getFillable(),
65
            'use_base_model' => 'use '.$this->getRootNamespace().'\BaseModel;',
66
        ]);
67
    }
68
69
    /**
70
     * Get the fillable attributes.
71
     *
72
     * @return string
73
     */
74
    public function getFillable()
75
    {
76
        if (! $this->fillable) {
0 ignored issues
show
Documentation introduced by
The property fillable does not exist on object<Milkmeowo\Framewo...erators\ModelGenerator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
77
            return '[]';
78
        }
79
        $results = '['.PHP_EOL;
80
81
        foreach ($this->getSchemaParser()->toArray() as $column => $value) {
82
            $results .= "\t\t'{$column}',".PHP_EOL;
83
        }
84
85
        return $results."\t".']';
86
    }
87
88
    /**
89
     * Get schema parser.
90
     *
91
     * @return SchemaParser
92
     */
93
    public function getSchemaParser()
94
    {
95
        return new SchemaParser($this->fillable);
0 ignored issues
show
Documentation introduced by
The property fillable does not exist on object<Milkmeowo\Framewo...erators\ModelGenerator>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
96
    }
97
}
98