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.
Completed
Push — master ( 3594bb...2ccb65 )
by .
15:42
created

ModelMakeCommand::fire()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
1
<?php
2
3
namespace duxet\Rethinkdb\Console\Model;
4
5
use Illuminate\Foundation\Console\ModelMakeCommand as LaravelMakeModelCommand;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class ModelMakeCommand extends LaravelMakeModelCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'make:rethink-model';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Create a new Rethinkdb model class';
23
24
    /**
25
     * The type of class being generated.
26
     *
27
     * @var string
28
     */
29
    protected $type = 'Model';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return void
35
     */
36
    public function fire()
37
    {
38
        if (parent::fire() !== false) {
39
            if ($this->option('migration')) {
40
                $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, class_basename() does only seem to accept string|object, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
41
42
                $this->call('make:rethink-migration', ['name' => "create_{$table}_table", '--create' => $table]);
43
            }
44
        }
45
    }
46
47
    /**
48
     * Get the stub file for the generator.
49
     *
50
     * @return string
51
     */
52
    protected function getStub()
53
    {
54
        return __DIR__.'/stubs/model.stub';
55
    }
56
57
    /**
58
     * Get the default namespace for the class.
59
     *
60
     * @param string $rootNamespace
61
     *
62
     * @return string
63
     */
64
    protected function getDefaultNamespace($rootNamespace)
65
    {
66
        return $rootNamespace;
67
    }
68
69
    /**
70
     * Get the console command options.
71
     *
72
     * @return array
73
     */
74
    protected function getOptions()
75
    {
76
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(array('migr...file for the model.')); (string[][]) is incompatible with the return type of the parent method Illuminate\Foundation\Co...MakeCommand::getOptions of type array<string|null>[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
77
            ['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'],
78
        ];
79
    }
80
}
81