Passed
Push — master ( 28f242...472b4c )
by Gabriel
04:44
created

HasPathsTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 49
ccs 12
cts 15
cp 0.8
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initPaths() 0 10 3
A setPath() 0 3 1
A path() 0 3 1
A paths() 0 3 1
1
<?php
2
3
namespace ByTIC\Migrations\Migrator\Traits;
4
5
use ByTIC\Migrations\Utility\Helper;
6
7
/**
8
 * Trait HasPathsTrait
9
 * @package ByTIC\Migrations\Migrator\Traits
10
 */
11
trait HasPathsTrait
12
{
13
14
    /**
15
     * Register a custom migration path.
16
     *
17
     * @param string $path
18
     * @param string $type
19
     */
20
    public function path($path, $type = 'migrations')
21
    {
22
        $this->getConfig()->path($path, $type);
0 ignored issues
show
Bug introduced by
It seems like getConfig() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        $this->/** @scrutinizer ignore-call */ 
23
               getConfig()->path($path, $type);
Loading history...
23
    }
24
25
    /**
26
     * Register a custom migration path.
27
     *
28
     * @param string $path
29
     * @param string $type
30
     */
31 2
    public function setPath($path, $type = 'migrations')
32
    {
33 2
        $this->getConfig()->setPath($path, $type);
34 2
    }
35
36
    /**
37
     * Get all of the custom migration paths.
38
     *
39
     * @param string $type
40
     * @return array
41
     */
42 1
    public function paths($type = 'migrations')
43
    {
44 1
        return $this->getConfig()->paths($type);
45
    }
46
47
    /**
48
     * @param string $type
49
     */
50 2
    protected function initPaths($type = 'migrations')
51
    {
52 2
        $paths = [];
53 2
        if (in_array($type, ['migrations', 'seeds'])) {
54 2
            $test = Helper::normalizePath(Helper::getBasePath(), 'database', $type);
55 2
            if (is_dir($test)) {
56 2
                $paths[] = $test;
57
            }
58
        }
59 2
        $this->setPath($paths, $type);
0 ignored issues
show
Bug introduced by
$paths of type array|string[] is incompatible with the type string expected by parameter $path of ByTIC\Migrations\Migrato...asPathsTrait::setPath(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
        $this->setPath(/** @scrutinizer ignore-type */ $paths, $type);
Loading history...
60 2
    }
61
}
62