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.

RoutesGenerator::getBasePath()   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
use Illuminate\Filesystem\Filesystem;
6
7
class RoutesGenerator extends Generator
8
{
9
    public $routesPlaceholder = '//:end-routes:';
10
11
    /**
12
     * Get stub name.
13
     *
14
     * @var string
15
     */
16
    protected $stub = 'routes/web';
17
18
    protected $webLumenStub = 'routes/web.lumen';
19
20
    protected $webLaravelStub = 'routes/web.laravel';
21
22
    protected $apiStub = 'routes/api';
23
24
    protected $webPathConfigNode = 'routes.web';
25
26
    protected $apiPathConfigNode = 'routes.api';
27
28
    public function run()
29
    {
30
        $filesystem = new Filesystem();
31
32
        $webStub = is_lumen() ? $this->webLumenStub : $this->webLaravelStub;
33
34
        $webRoute = $filesystem->get($this->getWebPath());
35
        $filesystem->put($this->getWebPath(),
36
            str_replace($this->routesPlaceholder, $this->getStub($webStub), $webRoute));
37
38
        $apiRoute = $filesystem->get($this->getApiPath());
39
        $filesystem->put($this->getApiPath(),
40
            str_replace($this->routesPlaceholder, $this->getStub($this->apiStub), $apiRoute));
41
    }
42
43
    /**
44
     * Get destination path for generated file.
45
     *
46
     * @return string
47
     */
48
    public function getWebPath()
49
    {
50
        return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->webPathConfigNode, true).'.php';
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConfigGeneratorClassPath() instead of getWebPath()). 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...
51
    }
52
53
    /**
54
     * Get base path of destination file.
55
     *
56
     * @return string
57
     */
58
    public function getBasePath()
59
    {
60
        return app()->basePath().'/routes';
61
    }
62
63
    /**
64
     * Get stub template for generated file.
65
     *
66
     * @param string $stub
67
     * @return string
68
     */
69
    public function getStub($stub = null)
70
    {
71
        $stub = isset($stub) ? $stub : $this->stub;
72
        $path = config('repository.generator.stubsOverridePath', __DIR__);
73
74
        if (! file_exists($path.'/Stubs/'.$stub.'.stub')) {
75
            $path = __DIR__;
76
        }
77
78
        return ( new Stub($path.'/Stubs/'.$stub.'.stub', $this->getReplacements()) )->render();
79
    }
80
81
    public function getReplacements()
82
    {
83
        return array_merge(parent::getReplacements(), [
84
            'lowerclass'  => str_plural(strtolower($this->getClass())),
85
            'controller'  => $this->getControllerName(),
86
            'placeholder' => $this->routesPlaceholder,
87
        ]);
88
    }
89
90
    public function getControllerName()
91
    {
92
        $controllerGenerator = new ControllerGenerator([
93
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...rators\RoutesGenerator>. 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...
94
        ]);
95
96
        $controllerName = $controllerGenerator->getControllerName().'Controller';
97
98
        return $controllerName;
99
    }
100
101
    public function getApiPath()
102
    {
103
        return $this->getBasePath().'/'.parent::getConfigGeneratorClassPath($this->apiPathConfigNode, true).'.php';
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConfigGeneratorClassPath() instead of getApiPath()). 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...
104
    }
105
106
    public function getPathConfigNode()
107
    {
108
        // TODO: Implement getPathConfigNode() method.
109
    }
110
}
111