HasPathsTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 57
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A paths() 0 3 1
A addBasePath() 0 4 1
A path() 0 5 2
A initPaths() 0 10 3
A setPath() 0 4 2
1
<?php
2
3
namespace ByTIC\Migrations\Config\Traits;
4
5
use ByTIC\Migrations\Utility\Helper;
6
7
/**
8
 * Trait HasPathsTrait
9
 * @package ByTIC\Migrations\Config\Traits
10
 */
11
trait HasPathsTrait
12
{
13
    /**
14
     * @param $path
15
     */
16 1
    public function addBasePath($path)
17
    {
18 1
        $this->setPath($path . DIRECTORY_SEPARATOR . 'migrations', 'migrations');
19 1
        $this->setPath($path . DIRECTORY_SEPARATOR . 'seeds', 'seeds');
20 1
    }
21
22
    /**
23
     * @param string $type
24
     */
25 2
    public function initPaths($type = 'migrations')
26
    {
27 2
        $paths = [];
28 2
        if (in_array($type, ['migrations', 'seeds'])) {
29 2
            $test = Helper::normalizePath(Helper::getBasePath(), 'database', $type);
30 2
            if (is_dir($test)) {
31 2
                $paths[] = $test;
32
            }
33
        }
34 2
        $this->setPath($paths, $type);
35 2
    }
36
37
    /**
38
     * @param $type
39
     * @param $path
40
     */
41 3
    public function setPath($path, $type = 'migrations')
42
    {
43 3
        $path = is_array($path) ? $path : [$path];
44 3
        $this->params['paths'][$type] = $path;
0 ignored issues
show
Bug Best Practice introduced by
The property params does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45 3
    }
46
47
    /**
48
     * Register a custom migration path.
49
     *
50
     * @param string $path
51
     * @param string $type
52
     * @return void
53
     */
54 1
    public function path($path, $type = 'migrations')
55
    {
56 1
        $existing = $this->params['paths'][$type];
57 1
        $existing = is_array($existing) ? $existing : [$existing];
58 1
        $this->params['paths'][$type] = array_unique(array_merge($existing, [$path]));
0 ignored issues
show
Bug Best Practice introduced by
The property params does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
59 1
    }
60
61
    /**
62
     * @param string $type
63
     * @return mixed
64
     */
65 2
    public function paths($type = 'migrations')
66
    {
67 2
        return $this->params['paths'][$type];
68
    }
69
}