Completed
Pull Request — master (#348)
by Martin
03:05
created

MakeFactoryCommand::getFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Commands;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Support\Stub;
7
use Nwidart\Modules\Traits\ModuleCommandTrait;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class MakeFactoryCommand extends GeneratorCommand
11
{
12
    use ModuleCommandTrait;
13
14
    /**
15
     * The name of argument name.
16
     *
17
     * @var string
18
     */
19
    protected $argumentName = 'name';
20
21
    /**
22
     * The console command name.
23
     *
24
     * @var string
25
     */
26
    protected $name = 'module:make-factory';
27
28
    /**
29
     * The console command description.
30
     *
31
     * @var string
32
     */
33
    protected $description = 'Create a new model factory for the specified module.';
34
35
    /**
36
     * Get the console command arguments.
37
     *
38
     * @return array
39
     */
40 59
    protected function getArguments()
41
    {
42
        return array(
43 59
            array('name', InputArgument::REQUIRED, 'The name of the factory.'),
44
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
45
        );
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51 2
    protected function getTemplateContents()
52
    {
53 2
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
0 ignored issues
show
Unused Code introduced by
$module is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
55 2
        return (new Stub('/factory.stub'))->render();
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61 2
    protected function getDestinationFilePath()
62
    {
63 2
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
64
65
        // $factoryPath = $this->laravel['modules']->config('paths.generator.factories');
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
67 2
        return $path . 'Database/factories/' . $this->getFileName();
68
    }
69
70
    /**
71
     * @return string
72
     */
73 2
    private function getFileName()
74
    {
75 2
        return Str::studly($this->argument('name')) . '.php';
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, Illuminate\Support\Str::studly() does only seem to accept string, 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...
76
    }
77
}
78