Completed
Push — master ( 78b3b4...1185ef )
by Fumio
02:21
created

MakeCommandTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A chooseSkeleton() 0 12 3
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel\Console;
4
5
use InvalidArgumentException;
6
7
trait MakeCommandTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    //protected $skeletons = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
13
14
    /**
15
     * @var string
16
     */
17
    //protected $default_skeleton;
18
19
    /**
20
     * Choose skeleton by command line parameter or dialog.
21
     *
22
     * @param string $skeleton
23
     *
24
     * @return string
25
     */
26 3
    protected function chooseSkeleton($skeleton)
27
    {
28 3
        if ($skeleton) {
29 3
            if (!in_array($skeleton, $this->skeletons)) {
0 ignored issues
show
Bug introduced by
The property skeletons does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
                throw new InvalidArgumentException("Skeleton '$skeleton' is not found.");
31
            }
32 3
        } else {
33
            $skeleton = $this->choice('Skeleton type', $this->skeletons, array_search($this->default_skeleton, $this->skeletons));
0 ignored issues
show
Bug introduced by
The property default_skeleton does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like choice() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
        }
35
36 3
        return $skeleton;
37
    }
38
}
39