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.

ValidatorGenerator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootNamespace() 4 4 1
A getPathConfigNode() 4 4 1
A getPath() 4 4 1
A getBasePath() 4 4 1
A getReplacements() 6 6 1
A getRules() 13 13 3
A getSchemaParser() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Milkmeowo\Framework\Repository\Generators;
4
5
use Milkmeowo\Framework\Repository\Generators\Migrations\RulesParser;
6
7 View Code Duplication
class ValidatorGenerator extends Generator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * Get stub name.
11
     *
12
     * @var string
13
     */
14
    protected $stub = 'validator/validator';
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 'validators';
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().'Validator.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
            'rules' => $this->getRules(),
65
        ]);
66
    }
67
68
    /**
69
     * Get the rules.
70
     *
71
     * @return string
72
     */
73
    public function getRules()
74
    {
75
        if (! $this->rules) {
0 ignored issues
show
Documentation introduced by
The property rules does not exist on object<Milkmeowo\Framewo...ors\ValidatorGenerator>. 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...
76
            return '[]';
77
        }
78
        $results = '['.PHP_EOL;
79
80
        foreach ($this->getSchemaParser()->toArray() as $column => $value) {
81
            $results .= "\t\t'{$column}'\t=>'\t{$value}',".PHP_EOL;
82
        }
83
84
        return $results."\t".']';
85
    }
86
87
    /**
88
     * Get schema parser.
89
     *
90
     * @return RulesParser
91
     */
92
    public function getSchemaParser()
93
    {
94
        return new RulesParser($this->rules);
0 ignored issues
show
Documentation introduced by
The property rules does not exist on object<Milkmeowo\Framewo...ors\ValidatorGenerator>. 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...
95
    }
96
}
97