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.

ControllerGenerator::getPluralName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Milkmeowo\Framework\Repository\Generators;
4
5
class ControllerGenerator extends Generator
6
{
7
    /**
8
     * Get stub name.
9
     *
10
     * @var string
11
     */
12
    protected $stub = 'controller/controller';
13
14
    /**
15
     * Get root namespace.
16
     *
17
     * @return string
18
     */
19
    public function getRootNamespace()
20
    {
21
        return str_replace('/', '\\', 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...
22
    }
23
24
    /**
25
     * Get generator path config node.
26
     *
27
     * @return string
28
     */
29
    public function getPathConfigNode()
30
    {
31
        return 'controllers';
32
    }
33
34
    /**
35
     * Get destination path for generated file.
36
     *
37
     * @return string
38
     */
39
    public function getPath()
40
    {
41
        return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true).'/'.$this->getControllerName().'Controller.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...
42
    }
43
44
    /**
45
     * Get base path of destination file.
46
     *
47
     * @return string
48
     */
49
    public function getBasePath()
50
    {
51
        return config('repository.generator.basePath', app()->path());
52
    }
53
54
    /**
55
     * Gets controller name based on model.
56
     *
57
     * @return string
58
     */
59
    public function getControllerName()
60
    {
61
        return ucfirst($this->getPluralName());
62
    }
63
64
    /**
65
     * Gets plural name based on model.
66
     *
67
     * @return string
68
     */
69
    public function getPluralName()
70
    {
71
        return str_plural(lcfirst(ucwords($this->getClass())));
72
    }
73
74
    /**
75
     * Get array replacements.
76
     *
77
     * @return array
78
     */
79
    public function getReplacements()
80
    {
81
        return array_merge(parent::getReplacements(), [
82
            'controller' => $this->getControllerName(),
83
            'plural'     => $this->getPluralName(),
84
            'singular'   => $this->getSingularName(),
85
            'validator'  => $this->getValidator(),
86
            'repository' => $this->getRepository(),
87
            'appname'    => $this->getAppNamespace(),
88
        ]);
89
    }
90
91
    /**
92
     * Gets singular name based on model.
93
     *
94
     * @return string
95
     */
96
    public function getSingularName()
97
    {
98
        return str_singular(lcfirst(ucwords($this->getClass())));
99
    }
100
101
    /**
102
     * Gets validator full class name.
103
     *
104
     * @return string
105
     */
106
    public function getValidator()
107
    {
108
        $validatorGenerator = new ValidatorGenerator([
109
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...rs\ControllerGenerator>. 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...
110
        ]);
111
112
        $validator = $validatorGenerator->getRootNamespace().'\\'.$validatorGenerator->getName();
113
114
        return 'use '.str_replace([
115
            '\\',
116
            '/',
117
        ], '\\', $validator).'Validator;';
118
    }
119
120
    /**
121
     * Gets repository full class name.
122
     *
123
     * @return string
124
     */
125
    public function getRepository()
126
    {
127
        $repositoryGenerator = new RepositoryInterfaceGenerator([
128
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...rs\ControllerGenerator>. 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...
129
        ]);
130
131
        $repository = $repositoryGenerator->getRootNamespace().'\\'.$repositoryGenerator->getName();
132
133
        return 'use '.str_replace([
134
            '\\',
135
            '/',
136
        ], '\\', $repository).'Repository;';
137
    }
138
}
139