Passed
Pull Request — master (#65)
by Arman
03:48
created

MigrationTemplate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 116
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 1
A drop() 0 12 1
A rename() 0 17 1
A alter() 0 19 1
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.7.0
13
 */
14
15
namespace Quantum\Migration;
16
17
/**
18
 * Class MigrationTable
19
 * @package Quantum\Migration
20
 */
21
class MigrationTemplate
22
{
23
24
    /**
25
     * Create migration template
26
     * @param string $className
27
     * @param string $tableName
28
     * @return string
29
     */
30
    public static function create($className, $tableName)
31
    {
32
        return '<?php
33
34
use Quantum\Migration\QtMigration;
35
use Quantum\Factory\TableFactory;
36
use Quantum\Libraries\Database\Schema\Type;
37
use Quantum\Libraries\Database\Schema\Key;
38
39
40
class ' . ucfirst($className) . ' extends QtMigration
41
{
42
    
43
    public function up(?TableFactory $tableFactory) {
44
        $table = $tableFactory->create(\'' . $tableName . '\');
45
    }
46
    
47
    public function down(?TableFactory $tableFactory)
48
    {
49
        $tableFactory->drop(\'' . $tableName . '\');
50
    }
51
52
}
53
       
54
        ';
55
    }
56
57
    /**
58
     * Alter migration template
59
     * @param string $className
60
     * @param string $tableName
61
     * @return string
62
     */
63
    public static function alter($className, $tableName)
64
    {
65
        return '<?php
66
67
use Quantum\Migration\QtMigration;
68
use Quantum\Factory\TableFactory;
69
use Quantum\Libraries\Database\Type;
70
use Quantum\Libraries\Database\Schema\Key;
71
72
class ' . ucfirst($className) . ' extends QtMigration
73
{
74
    
75
    public function up(?TableFactory $tableFactory) {
76
        $table = $tableFactory->get(\'' . $tableName . '\');
77
    }
78
    
79
    public function down(?TableFactory $tableFactory)
80
    {
81
        $table = $tableFactory->get(\'' . $tableName . '\');
82
    }
83
84
}
85
       
86
        ';
87
    }
88
89
    /**
90
     * Rename migration template
91
     * @param string $className
92
     * @param string $tableName
93
     * @return string
94
     */
95
    public static function rename($className, $tableName)
96
    {
97
        return '<?php
98
99
use Quantum\Migration\QtMigration;
100
use Quantum\Factory\TableFactory;
101
102
class ' . ucfirst($className) . ' extends QtMigration
103
{
104
    
105
    public function up(?TableFactory $tableFactory) {
106
        $tableFactory->rename(\'' . $tableName . '\', $newName);
107
    }
108
    
109
    public function down(?TableFactory $tableFactory)
110
    {
111
        $tableFactory->rename($newName, \'' . $tableName . '\');
112
    }
113
114
}
115
       
116
        ';
117
    }
118
119
    /**
120
     * Drop migration template
121
     * @param string $className
122
     * @param string $tableName
123
     * @return string
124
     */
125
    public static function drop($className, $tableName)
126
    {
127
        return '<?php
128
129
use Quantum\Migration\QtMigration;
130
use Quantum\Factory\TableFactory;
131
132
class ' . ucfirst($className) . ' extends QtMigration
133
{
134
    
135
    public function up(?TableFactory $tableFactory) {
136
        $tableFactory->drop(\'' . $tableName . '\');
137
    }
138
    
139
    public function down(?TableFactory $tableFactory)
140
    {
141
        //
142
    }
143
144
}
145
       
146
        ';
147
    }
148
149
}
150