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.

BindingsGenerator::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 BindingsGenerator extends Generator
8
{
9
    /**
10
     * The placeholder for repository bindings.
11
     *
12
     * @var string
13
     */
14
    public $bindPlaceholder = '//:end-bindings:';
15
    /**
16
     * Get stub name.
17
     *
18
     * @var string
19
     */
20
    protected $stub = 'bindings/bindings';
21
22
    /**
23
     * Run the generator.
24
     *
25
     * @return int
26
     */
27
    public function run()
28
    {
29
        $filesystem = new Filesystem();
30
31
        // Add entity repository binding to the repository service provider
32
        $provider = $filesystem->get($this->getPath());
33
        $repositoryInterface = '\\'.$this->getRepository().'::class';
34
        $repositoryEloquent = '\\'.$this->getEloquentRepository().'::class';
35
36
        return $filesystem->put($this->getPath(), str_replace($this->bindPlaceholder, "\$this->app->bind({$repositoryInterface}, $repositoryEloquent);".PHP_EOL.'        '.$this->bindPlaceholder, $provider));
37
    }
38
39
    /**
40
     * Get destination path for generated file.
41
     *
42
     * @return string
43
     */
44
    public function getPath()
45
    {
46
        return $this->getBasePath().'/Providers/'.parent::getConfigGeneratorClassPath($this->getPathConfigNode(), true).'.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...
47
    }
48
49
    /**
50
     * Get base path of destination file.
51
     *
52
     * @return string
53
     */
54
    public function getBasePath()
55
    {
56
        return config('repository.generator.basePath', app()->path());
57
    }
58
59
    /**
60
     * Get generator path config node.
61
     *
62
     * @return string
63
     */
64
    public function getPathConfigNode()
65
    {
66
        return 'provider';
67
    }
68
69
    /**
70
     * Gets repository full class name.
71
     *
72
     * @return string
73
     */
74
    public function getRepository()
75
    {
76
        $repositoryGenerator = new RepositoryInterfaceGenerator([
77
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...tors\BindingsGenerator>. 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...
78
        ]);
79
80
        $repository = $repositoryGenerator->getRootNamespace().'\\'.$repositoryGenerator->getName();
81
82
        return str_replace([
83
            '\\',
84
            '/',
85
        ], '\\', $repository).'Repository';
86
    }
87
88
    /**
89
     * Gets eloquent repository full class name.
90
     *
91
     * @return string
92
     */
93
    public function getEloquentRepository()
94
    {
95
        $repositoryGenerator = new RepositoryEloquentGenerator([
96
            'name' => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...tors\BindingsGenerator>. 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...
97
        ]);
98
99
        $repository = $repositoryGenerator->getRootNamespace().'\\'.$repositoryGenerator->getName();
100
101
        return str_replace([
102
            '\\',
103
            '/',
104
        ], '\\', $repository).'RepositoryEloquent';
105
    }
106
107
    /**
108
     * Get root namespace.
109
     *
110
     * @return string
111
     */
112
    public function getRootNamespace()
113
    {
114
        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...
115
    }
116
117
    /**
118
     * Get array replacements.
119
     *
120
     * @return array
121
     */
122
    public function getReplacements()
123
    {
124
        return array_merge(parent::getReplacements(), [
125
            'repository' => $this->getRepository(),
126
            'eloquent' => $this->getEloquentRepository(),
127
            'placeholder' => $this->bindPlaceholder,
128
        ]);
129
    }
130
}
131