Completed
Push — master ( 4deee6...b383ba )
by Zach
05:43 queued 03:44
created

PathHelpers   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
get() 0 1 ?
A getDatabaseDirectory() 0 4 1
A getMigrationDirectory() 0 4 1
A getFactoryDirectory() 0 4 1
A getSeedDirectory() 0 4 1
A getAllDatabaseDirectories() 0 9 1
A getConsoleDirectory() 0 7 1
A getCommandsDirectory() 0 7 1
1
<?php
2
3
namespace Yarak\Config;
4
5
use Yarak\Helpers\Str;
6
7
trait PathHelpers
8
{
9
    /**
10
     * Get a value from the config array.
11
     *
12
     * @param string|array $value
13
     *
14
     * @return mixed
15
     */
16
    abstract public function get($value);
17
18
    /**
19
     * Return the database directory path.
20
     *
21
     * @return string
22
     */
23
    public function getDatabaseDirectory()
24
    {
25
        return Str::append($this->get(['application', 'databaseDir']), '/');
26
    }
27
28
    /**
29
     * Return the migration directory path.
30
     *
31
     * @param string $path
32
     *
33
     * @return string
34
     */
35
    public function getMigrationDirectory($path = '')
36
    {
37
        return $this->getDatabaseDirectory().'migrations/'.$path;
38
    }
39
40
    /**
41
     * Return the factory directory path.
42
     *
43
     * @param string $path
44
     *
45
     * @return string
46
     */
47
    public function getFactoryDirectory($path = '')
48
    {
49
        return $this->getDatabaseDirectory().'factories/'.$path;
50
    }
51
52
    /**
53
     * Return the seeds directory path.
54
     *
55
     * @param string $path
56
     *
57
     * @return string
58
     */
59
    public function getSeedDirectory($path = '')
60
    {
61
        return $this->getDatabaseDirectory().'seeds/'.$path;
62
    }
63
64
    /**
65
     * Make database directory structure if it doesn't exist.
66
     */
67
    public function getAllDatabaseDirectories()
68
    {
69
        return [
70
            'database'   => $this->getDatabaseDirectory(),
71
            'migrations' => $this->getMigrationDirectory(),
72
            'factories'  => $this->getFactoryDirectory(),
73
            'seeds'      => $this->getSeedDirectory(),
74
        ];
75
    }
76
77
    /**
78
     * Get the console directory path.
79
     *
80
     * @param string $path
81
     *
82
     * @return string
83
     */
84
    public function getConsoleDirectory($path = '')
85
    {
86
        return Str::append(
87
            $this->get(['application', 'consoleDir']),
88
            '/'
89
        ).$path;
90
    }
91
92
    /**
93
     * Get the commands directory path.
94
     *
95
     * @param string $path
96
     *
97
     * @return string
98
     */
99
    public function getCommandsDirectory($path = '')
100
    {
101
        return Str::append(
102
            $this->get(['application', 'consoleDir']),
103
            '/'
104
        ).'commands/'.$path;
105
    }
106
}
107