Completed
Push — dev ( 122982...5e45c8 )
by Zach
02:18
created

PathHelpers::addFinalSlash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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