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.

RepositoryEloquentGenerator::getPresenter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Milkmeowo\Framework\Repository\Generators;
4
5
use Milkmeowo\Framework\Repository\Generators\Migrations\SchemaParser;
6
7
class RepositoryEloquentGenerator extends Generator
8
{
9
    /**
10
     * Get stub name.
11
     *
12
     * @var string
13
     */
14
    protected $stub = 'repository/eloquent';
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 'repositories';
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(),
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
            true).'/'.$this->getName().'RepositoryEloquent.php';
45
    }
46
47
    /**
48
     * Get base path of destination file.
49
     *
50
     * @return string
51
     */
52
    public function getBasePath()
53
    {
54
        return config('repository.generator.basePath', app()->path());
55
    }
56
57
    /**
58
     * Get array replacements.
59
     *
60
     * @return array
61
     */
62
    public function getReplacements()
63
    {
64
        $repository = parent::getRootNamespace().parent::getConfigGeneratorClassPath('interfaces').'\\'.$this->name.'Repository;';
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getRootNamespace() instead of getReplacements()). Are you sure this is correct? If so, you might want to change this to $this->getRootNamespace().

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...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConfigGeneratorClassPath() instead of getReplacements()). 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...
65
        $repository = str_replace([
66
            '\\',
67
            '/',
68
        ], '\\', $repository);
69
70
        return array_merge(parent::getReplacements(), [
71
            'fillable'      => $this->getFillable(),
72
            'use_validator' => $this->getValidatorUse(),
73
            'validator'     => $this->getValidatorMethod(),
74
            'use_presenter' => $this->getPresenterUse(),
75
            'presenter'     => $this->getPresenterMethod(),
76
            'criteria'      => $this->getCriteria(),
77
            'repository'    => $repository,
78
            'model'         => isset($this->options['model']) ? $this->options['model'] : '',
79
        ]);
80
    }
81
82
    /**
83
     * Get the fillable attributes.
84
     *
85
     * @return string
86
     */
87
    public function getFillable()
88
    {
89
        if (! $this->fillable) {
0 ignored issues
show
Documentation introduced by
The property fillable does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
90
            return '[]';
91
        }
92
        $results = '['.PHP_EOL;
93
94
        foreach ($this->getSchemaParser()->toArray() as $column => $value) {
95
            $results .= "\t\t'{$column}',".PHP_EOL;
96
        }
97
98
        return $results."\t".']';
99
    }
100
101
    /**
102
     * Get schema parser.
103
     *
104
     * @return SchemaParser
105
     */
106
    public function getSchemaParser()
107
    {
108
        return new SchemaParser($this->fillable);
0 ignored issues
show
Documentation introduced by
The property fillable does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
109
    }
110
111
    /**
112
     * @return string
113
     */
114
    public function getValidatorUse()
115
    {
116
        $validator = $this->getValidator();
117
118
        return "use {$validator};";
119
    }
120
121
    /**
122
     * @return string
123
     */
124 View Code Duplication
    public function getValidator()
0 ignored issues
show
Duplication introduced by
This method 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...
125
    {
126
        $validatorGenerator = new ValidatorGenerator([
127
            'name'  => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
128
            'rules' => $this->rules,
0 ignored issues
show
Documentation introduced by
The property rules does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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
            'force' => $this->force,
0 ignored issues
show
Documentation introduced by
The property force does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
130
        ]);
131
132
        $validator = $validatorGenerator->getRootNamespace().'\\'.$validatorGenerator->getName();
133
134
        return str_replace([
135
            '\\',
136
            '/',
137
        ], '\\', $validator).'Validator';
138
    }
139
140
    /**
141
     * @return string
142
     */
143 View Code Duplication
    public function getValidatorMethod()
0 ignored issues
show
Duplication introduced by
This method 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...
144
    {
145
        if ($this->validator != 'yes') {
0 ignored issues
show
Documentation introduced by
The property validator does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
146
            return '';
147
        }
148
149
        $class = $this->getClass();
150
151
        return '/**'.PHP_EOL.'     * Specify Validator class name.'.PHP_EOL.'     *'.PHP_EOL.'     * @return mixed'.PHP_EOL.'     */'.PHP_EOL.'    public function validator()'.PHP_EOL.'    {'.PHP_EOL.'        return '.$class.'Validator::class;'.PHP_EOL.'    }';
152
    }
153
154
    /**
155
     * @return string
156
     */
157
    public function getPresenterUse()
158
    {
159
        $presenter = $this->getPresenter();
160
161
        return "use {$presenter};";
162
    }
163
164
    /**
165
     * @return string
166
     */
167 View Code Duplication
    public function getPresenter()
0 ignored issues
show
Duplication introduced by
This method 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...
168
    {
169
        $presenterGenerator = new PresenterGenerator([
170
            'name'  => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
171
            'rules' => $this->rules,
0 ignored issues
show
Documentation introduced by
The property rules does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
172
            'force' => $this->force,
0 ignored issues
show
Documentation introduced by
The property force does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
173
        ]);
174
        $presenter = $presenterGenerator->getRootNamespace().'\\'.$presenterGenerator->getName();
175
176
        return str_replace([
177
            '\\',
178
            '/',
179
        ], '\\', $presenter).'Presenter';
180
    }
181
182
    /**
183
     * @return string
184
     */
185 View Code Duplication
    public function getPresenterMethod()
0 ignored issues
show
Duplication introduced by
This method 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...
186
    {
187
        if ($this->presenter != 'yes') {
0 ignored issues
show
Documentation introduced by
The property presenter does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
188
            return '';
189
        }
190
        $class = $this->getClass();
191
192
        return '/**'.PHP_EOL.'     * Specify Presenter class name.'.PHP_EOL.'     *'.PHP_EOL.'     * @return mixed'.PHP_EOL.'     */'.PHP_EOL.'    public function presenter()'.PHP_EOL.'    {'.PHP_EOL.'        return '.$class.'Presenter::class;'.PHP_EOL.'    }';
193
    }
194
195
    /**
196
     * @return string
197
     */
198 View Code Duplication
    public function getCriteria()
0 ignored issues
show
Duplication introduced by
This method 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...
199
    {
200
        $criteriaGenerator = new CriteriaGenerator([
201
            'name'  => $this->name,
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
202
            'force' => $this->force,
0 ignored issues
show
Documentation introduced by
The property force does not exist on object<Milkmeowo\Framewo...itoryEloquentGenerator>. 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...
203
        ]);
204
205
        $criteria = $criteriaGenerator->getRootNamespace().'\\'.$criteriaGenerator->getName();
206
207
        return str_replace([
208
            '\\',
209
            '/',
210
        ], '\\', $criteria).'Criteria';
211
    }
212
}
213