Completed
Pull Request — master (#1088)
by
unknown
09:38
created

Command::appendable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Generators;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Commands\GeneratorCommand;
7
8
abstract class Command extends GeneratorCommand
9
{
10
11
    /**
12
     * The name to be appended to the generated resources.
13
     *
14
     * @var null|string
15
     */
16
    protected $appendable;
17
18
    /**
19
     * Getter for appendable
20
     *
21
     * @return void
22
     */
23
    public function appendable()
24
    {
25
        return $this->appendable;
26
    }
27
28
    /**
29
     * Get and resolve the filename.
30
     *
31
     * @return string
32
     */
33
    protected function getFileName(): string
34
    {
35
36
        $name = Str::studly($this->argument($this->argumentName));
0 ignored issues
show
Bug introduced by
It seems like $this->argument($this->argumentName) targeting Illuminate\Console\Conce...ractsWithIO::argument() can also be of type array or null; 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...
37
        if ($this->appendable() && !Str::contains(strtolower($name), strtolower($this->appendable()))) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->appendable() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
38
            $name .= Str::studly($this->appendable());
39
        }
40
41
        return Str::singular(Str::studly($name));
42
    }
43
}
44