PathHelpers   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 138
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
get() 0 1 ?
has() 0 1 ?
validate() 0 1 ?
A getAppPath() 0 6 1
A getDatabaseDirectory() 0 6 1
A getMigrationDirectory() 0 4 1
A getFactoryDirectory() 0 4 1
A getSeedDirectory() 0 4 1
A getAllDatabaseDirectories() 0 9 1
A getConsoleDirectory() 0 9 1
A getCommandsDirectory() 0 11 2
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 true if config array has given value.
20
     *
21
     * @param mixed $value
22
     *
23
     * @return bool
24
     */
25
    abstract public function has($value);
26
27
    /**
28
     * Validate that a setting exists.
29
     *
30
     * @param array $settings
31
     *
32
     * @throws InvalidConfig
33
     */
34
    abstract public function validate(array $settings);
35
36
    /**
37
     * Return the app path.
38
     *
39
     * @return string
40
     */
41
    public function getAppPath()
42
    {
43
        $this->validate(['application', 'appDir']);
44
45
        return Str::append($this->get('application')->get('appDir'), '/');
46
    }
47
48
    /**
49
     * Return the database directory path.
50
     *
51
     * @return string
52
     */
53
    public function getDatabaseDirectory()
54
    {
55
        $this->validate(['application', 'databaseDir']);
56
57
        return Str::append($this->get('application')->get('databaseDir'), '/');
58
    }
59
60
    /**
61
     * Return the migration directory path.
62
     *
63
     * @param string $path
64
     *
65
     * @return string
66
     */
67
    public function getMigrationDirectory($path = '')
68
    {
69
        return $this->getDatabaseDirectory().'migrations/'.$path;
70
    }
71
72
    /**
73
     * Return the factory directory path.
74
     *
75
     * @param string $path
76
     *
77
     * @return string
78
     */
79
    public function getFactoryDirectory($path = '')
80
    {
81
        return $this->getDatabaseDirectory().'factories/'.$path;
82
    }
83
84
    /**
85
     * Return the seeds directory path.
86
     *
87
     * @param string $path
88
     *
89
     * @return string
90
     */
91
    public function getSeedDirectory($path = '')
92
    {
93
        return $this->getDatabaseDirectory().'seeds/'.$path;
94
    }
95
96
    /**
97
     * Make database directory structure if it doesn't exist.
98
     */
99
    public function getAllDatabaseDirectories()
100
    {
101
        return [
102
            'database'   => $this->getDatabaseDirectory(),
103
            'migrations' => $this->getMigrationDirectory(),
104
            'factories'  => $this->getFactoryDirectory(),
105
            'seeds'      => $this->getSeedDirectory(),
106
        ];
107
    }
108
109
    /**
110
     * Get the console directory path.
111
     *
112
     * @param string $path
113
     *
114
     * @return string
115
     */
116
    public function getConsoleDirectory($path = '')
117
    {
118
        $this->validate(['application', 'consoleDir']);
119
120
        return Str::append(
121
            $this->get('application')->get('consoleDir'),
122
            '/'
123
        ).$path;
124
    }
125
126
    /**
127
     * Get the commands directory path.
128
     *
129
     * @param string $path
130
     *
131
     * @return string
132
     */
133
    public function getCommandsDirectory($path = '')
134
    {
135
        if ($this->has(['application', 'commandsDir'])) {
136
            return Str::append(
137
                $this->get('application')->get('commandsDir'),
138
                '/'
139
            ).$path;
140
        }
141
142
        return $this->getConsoleDirectory().'commands/'.$path;
143
    }
144
}
145