Completed
Push — master ( 8f08c7...7bd638 )
by Mohamed
02:25
created

MicroboardPathResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveStubPath() 0 6 2
A getPath() 0 9 2
A pathOptions() 0 6 1
1
<?php
2
3
namespace Microboard\Foundations\Traits;
4
5
use Illuminate\Support\Str;
6
use Symfony\Component\Console\Input\InputOption;
7
8
trait MicroboardPathResolver
9
{
10
    /**
11
     * Resolve the fully-qualified path to the stub.
12
     *
13
     * @param string $stub
14
     * @return string
15
     */
16
    protected function resolveStubPath($stub)
17
    {
18
        return file_exists($customPath = $this->laravel->resourcePath(trim('views/vendors/microboard' . $stub, '/')))
0 ignored issues
show
Bug introduced by
The property laravel 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...
19
            ? $customPath
20
            : __DIR__ . '/../../..' . $stub;
21
    }
22
23
    /**
24
     * Get the destination class path.
25
     *
26
     * @param string $name
27
     * @return string
28
     */
29
    protected function getPath($name)
30
    {
31
        $name = Str::replaceFirst($this->rootNamespace(), '', $name);
0 ignored issues
show
Bug introduced by
It seems like rootNamespace() 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...
32
33
        return ($this->option('base_path') ?
0 ignored issues
show
Bug introduced by
The method option() does not exist on Microboard\Foundations\T...\MicroboardPathResolver. Did you maybe mean pathOptions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
                rtrim($this->option('base_path'), '\\/') . '/app' :
0 ignored issues
show
Bug introduced by
The method option() does not exist on Microboard\Foundations\T...\MicroboardPathResolver. Did you maybe mean pathOptions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
                $this->laravel['path']) .
36
            '/' . str_replace('\\', '/', $name) . '.php';
37
    }
38
39
    /**
40
     * Add base_path to command options.
41
     *
42
     * @return array
43
     */
44
    protected function pathOptions()
45
    {
46
        return [
47
            ['base_path', '', InputOption::VALUE_OPTIONAL, 'Change base path'],
48
        ];
49
    }
50
}
51