Completed
Push — dev ( 3ddbd6...175d0e )
by Zach
02:08
created

PathHelpers::getConsoleDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Config;
4
5
trait PathHelpers
6
{
7
    /**
8
     * Get a value from the config array.
9
     *
10
     * @param string|array $value
11
     *
12
     * @return mixed
13
     */
14
    abstract public function get($value);
15
16
    /**
17
     * Return the database directory path.
18
     *
19
     * @return string
20
     */
21
    public function getDatabaseDirectory()
22
    {
23
        return $this->addFinalSlash($this->get(['application', 'databaseDir']));
24
    }
25
26
    /**
27
     * Return the migration directory path.
28
     *
29
     * @param string $path
30
     *
31
     * @return string
32
     */
33
    public function getMigrationDirectory($path = '')
34
    {
35
        return $this->getDatabaseDirectory().'migrations/'.$path;
36
    }
37
38
    /**
39
     * Return the factory directory path.
40
     *
41
     * @param string $path
42
     *
43
     * @return string
44
     */
45
    public function getFactoryDirectory($path = '')
46
    {
47
        return $this->getDatabaseDirectory().'factories/'.$path;
48
    }
49
50
    /**
51
     * Return the seeds directory path.
52
     *
53
     * @param string $path
54
     *
55
     * @return string
56
     */
57
    public function getSeedDirectory($path = '')
58
    {
59
        return $this->getDatabaseDirectory().'seeds/'.$path;
60
    }
61
62
    /**
63
     * Make database directory structure if it doesn't exist.
64
     */
65
    public function getAllDatabaseDirectories()
66
    {
67
        return [
68
            'database'   => $this->getDatabaseDirectory(),
69
            'migrations' => $this->getMigrationDirectory(),
70
            'factories'  => $this->getFactoryDirectory(),
71
            'seeds'      => $this->getSeedDirectory(),
72
        ];
73
    }
74
75
    /**
76
     * Get the console directory path.
77
     *
78
     * @param string $path
79
     *
80
     * @return string
81
     */
82
    public function getConsoleDirectory($path = '')
83
    {
84
        return $this->addFinalSlash(
85
            $this->get(['application', 'consoleDir'])
86
        ).$path;
87
    }
88
89
    /**
90
     * Get the commands directory path.
91
     *
92
     * @param string $path
93
     *
94
     * @return string
95
     */
96
    public function getCommandsDirectory($path = '')
97
    {
98
        return $this->addFinalSlash(
99
            $this->get(['application', 'consoleDir'])
100
        ).'commands/'.$path;
101
    }
102
103
    /**
104
     * Add a final slash to a path if it doesn't exist.
105
     *
106
     * @param string $path
107
     *
108
     * @return string
109
     */
110
    protected function addFinalSlash($path)
111
    {
112
        if (substr($path, -1) !== '/') {
113
            $path .= '/';
114
        }
115
116
        return $path;
117
    }
118
}
119