Passed
Push — master ( aa397c...819f04 )
by Thomas
02:33
created

Migration::getRelativeFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Schemas\Naming;
4
5
use Carbon\Carbon;
6
use Webfactor\Laravel\Generators\Contracts\NamingAbstract;
7
8
class Migration extends NamingAbstract
9
{
10
    protected $fileName;
11
12
    /**
13
     * Migration constructor.
14
     * @param string $entity
15
     */
16
    public function __construct(string $entity)
17
    {
18
        parent::__construct($entity);
19
20
        $this->setFileName();
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function getClassName(): string
27
    {
28
        return 'Create' . ucfirst(str_plural($this->entity)) . 'Table';
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getTableName(): string
35
    {
36
        return snake_case(str_plural($this->entity));
37
    }
38
39
    /**
40
     * @return void
41
     */
42
    public function setFileName(): void
43
    {
44
        $this->fileName = Carbon::now()->format('Y_m_d_His') . '_' . snake_case($this->getClassName()) . '.php';
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getFileName(): string
51
    {
52
        return $this->fileName;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getPath(): string
59
    {
60
        return database_path('migrations');
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getRelativeFilePath(): string
67
    {
68
        return 'database/migrations/'.$this->getFileName();
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getStub(): string
75
    {
76
        return __DIR__ . '/../../../stubs/migration.stub';
77
    }
78
}
79