Completed
Push — master ( 63d8d6...28be9d )
by Raphael
11:25
created
src/Scaffolder/Compilers/AngularJs/RegisterControllerCompiler.php 3 patches
Doc Comments   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * Replace and store the Stub.
24 24
 	 *
25
-	 * @return string
25
+	 * @return RegisterControllerCompiler
26 26
 	 */
27 27
 	public function replaceAndStore()
28 28
 	{
@@ -114,6 +114,10 @@  discard block
 block discarded – undo
114 114
 	}
115 115
 	
116 116
 
117
+	/**
118
+	 * @param string $stubName
119
+	 * @param string $stubTag
120
+	 */
117 121
 	public function changeStubDataAndTag($stubName,$stubTag,$table_from)
118 122
 	{
119 123
 		$stubFile = File::get($this->stubsDirectory . '/Register/'.$stubName.'ControllerStub.php');
@@ -125,7 +129,7 @@  discard block
 block discarded – undo
125 129
 	 * Get output filename
126 130
 	 *
127 131
 	 *
128
-	 * @return $this
132
+	 * @return string
129 133
 	 */
130 134
 	protected function getOutputFilename()
131 135
 	{
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -10,130 +10,130 @@
 block discarded – undo
10 10
 
11 11
 class RegisterControllerCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'register_controller_';
14
-	protected $stubFilename = 'RegisterController.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'register_controller_';
14
+    protected $stubFilename = 'RegisterController.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this
31
-					->replaceFileUpload()
32
-					->replaceNewTags()
33
-					->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this
31
+                    ->replaceFileUpload()
32
+                    ->replaceNewTags()
33
+                    ->store(new FileToCompile(false, $this->modelData->modelHash));
34 34
 		
35
-	}
36
-
37
-	public function replaceNewTags()
38
-	{
39
-		foreach ($this->modelData->fields as $field)
40
-		{
41
-
42
-			if($field->type->ui == 'autoComplete' || $field->type->ui == 'multipleAutoComplete')
43
-			{
44
-				$this->stub = str_replace('{{table_from}}', $field->table_from, $this->stub);
45
-			}
46
-
47
-
48
-		}
49
-
50
-		return $this;
51
-	}
52
-
53
-	private function replaceFileUpload()
54
-	{
55
-		$fileStub = File::get($this->stubsDirectory . '/Register/FileRegisterControllerStub.php');
56
-		$this->stub = str_replace('{{file_upload}}', $fileStub, $this->stub);
57
-
58
-		$keyAutoComplete = $keyMultipleAutoComplete = $keyCheckbox = $keyCheckboxTree = false;
59
-
60
-		foreach ($this->modelData->fields as $field)
61
-		{
62
-
63
-			//Verifica os tipos de UI no model.json e realiza a troca das tags pelas funções JS se necessário
64
-			switch ($field->type->ui) {
65
-				case 'autoComplete':
66
-					$autoStub = $this->changeStubDataAndTag('AutoComplete', '{{auto_complete}}', $field->table_from);
67
-					$keyAutoComplete = true;
68
-					break;
69
-				case 'multipleAutoComplete':
70
-					$multipleAutoStub = $this->changeStubDataAndTag('MultipleAutoComplete','{{multiple_auto_complete}}',$field->table_from);
71
-					$keyMultipleAutoComplete = true;
72
-					break;
73
-				case 'checkbox':
74
-					$checkboxStub = $this->changeStubDataAndTag('Checkbox','{{checkbox}}', $field->table_from);
75
-					$keyCheckbox = true;
76
-					break;
77
-				case 'checkboxTree':
78
-					$checkboxTreeStub = $this->changeStubDataAndTag('CheckboxTree','{{checkbox_tree}}', $field->table_from);
79
-					$keyCheckboxTree = true;
80
-					break;
81
-				default:
82
-					break;
83
-			}
84
-
85
-			if($field->foreignKey)
86
-			{
87
-				$this->stub = str_replace('{{foreign_table}}', $field->foreignKey->table, $this->stub);
88
-			}
89
-
90
-
91
-		}
35
+    }
36
+
37
+    public function replaceNewTags()
38
+    {
39
+        foreach ($this->modelData->fields as $field)
40
+        {
41
+
42
+            if($field->type->ui == 'autoComplete' || $field->type->ui == 'multipleAutoComplete')
43
+            {
44
+                $this->stub = str_replace('{{table_from}}', $field->table_from, $this->stub);
45
+            }
46
+
47
+
48
+        }
49
+
50
+        return $this;
51
+    }
52
+
53
+    private function replaceFileUpload()
54
+    {
55
+        $fileStub = File::get($this->stubsDirectory . '/Register/FileRegisterControllerStub.php');
56
+        $this->stub = str_replace('{{file_upload}}', $fileStub, $this->stub);
57
+
58
+        $keyAutoComplete = $keyMultipleAutoComplete = $keyCheckbox = $keyCheckboxTree = false;
59
+
60
+        foreach ($this->modelData->fields as $field)
61
+        {
62
+
63
+            //Verifica os tipos de UI no model.json e realiza a troca das tags pelas funções JS se necessário
64
+            switch ($field->type->ui) {
65
+                case 'autoComplete':
66
+                    $autoStub = $this->changeStubDataAndTag('AutoComplete', '{{auto_complete}}', $field->table_from);
67
+                    $keyAutoComplete = true;
68
+                    break;
69
+                case 'multipleAutoComplete':
70
+                    $multipleAutoStub = $this->changeStubDataAndTag('MultipleAutoComplete','{{multiple_auto_complete}}',$field->table_from);
71
+                    $keyMultipleAutoComplete = true;
72
+                    break;
73
+                case 'checkbox':
74
+                    $checkboxStub = $this->changeStubDataAndTag('Checkbox','{{checkbox}}', $field->table_from);
75
+                    $keyCheckbox = true;
76
+                    break;
77
+                case 'checkboxTree':
78
+                    $checkboxTreeStub = $this->changeStubDataAndTag('CheckboxTree','{{checkbox_tree}}', $field->table_from);
79
+                    $keyCheckboxTree = true;
80
+                    break;
81
+                default:
82
+                    break;
83
+            }
84
+
85
+            if($field->foreignKey)
86
+            {
87
+                $this->stub = str_replace('{{foreign_table}}', $field->foreignKey->table, $this->stub);
88
+            }
89
+
90
+
91
+        }
92 92
 		
93
-		if(!$keyAutoComplete)
94
-		{
95
-			$this->stub = str_replace('{{auto_complete}}', ' ', $this->stub);
96
-		}
97
-
98
-		if(!$keyMultipleAutoComplete)
99
-		{
100
-			$this->stub = str_replace('{{multiple_auto_complete}}', ' ', $this->stub);
101
-		}
102
-
103
-		if(!$keyCheckbox)
104
-		{
105
-			$this->stub = str_replace('{{checkbox}}', ' ', $this->stub);
106
-		}			
107
-
108
-		if(!$keyCheckboxTree)
109
-		{
110
-			$this->stub = str_replace('{{checkbox_tree}}', ' ', $this->stub);
111
-		}
112
-
113
-		return $this;
114
-	}
93
+        if(!$keyAutoComplete)
94
+        {
95
+            $this->stub = str_replace('{{auto_complete}}', ' ', $this->stub);
96
+        }
97
+
98
+        if(!$keyMultipleAutoComplete)
99
+        {
100
+            $this->stub = str_replace('{{multiple_auto_complete}}', ' ', $this->stub);
101
+        }
102
+
103
+        if(!$keyCheckbox)
104
+        {
105
+            $this->stub = str_replace('{{checkbox}}', ' ', $this->stub);
106
+        }			
107
+
108
+        if(!$keyCheckboxTree)
109
+        {
110
+            $this->stub = str_replace('{{checkbox_tree}}', ' ', $this->stub);
111
+        }
112
+
113
+        return $this;
114
+    }
115 115
 	
116 116
 
117
-	public function changeStubDataAndTag($stubName,$stubTag,$table_from)
118
-	{
119
-		$stubFile = File::get($this->stubsDirectory . '/Register/'.$stubName.'ControllerStub.php');
120
-		$stubFile = str_replace('{{table_from}}', $table_from, $stubFile);
121
-		$this->stub = str_replace($stubTag, $stubFile, $this->stub);
122
-	}
123
-
124
-	/**
125
-	 * Get output filename
126
-	 *
127
-	 *
128
-	 * @return $this
129
-	 */
130
-	protected function getOutputFilename()
131
-	{
132
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
133
-
134
-		Directory::createIfNotExists($folder, 0755, true);
135
-
136
-		return $folder .$this->modelData->tableName . '_register.controller.js';
137
-	}
117
+    public function changeStubDataAndTag($stubName,$stubTag,$table_from)
118
+    {
119
+        $stubFile = File::get($this->stubsDirectory . '/Register/'.$stubName.'ControllerStub.php');
120
+        $stubFile = str_replace('{{table_from}}', $table_from, $stubFile);
121
+        $this->stub = str_replace($stubTag, $stubFile, $this->stub);
122
+    }
123
+
124
+    /**
125
+     * Get output filename
126
+     *
127
+     *
128
+     * @return $this
129
+     */
130
+    protected function getOutputFilename()
131
+    {
132
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
133
+
134
+        Directory::createIfNotExists($folder, 0755, true);
135
+
136
+        return $folder .$this->modelData->tableName . '_register.controller.js';
137
+    }
138 138
 
139 139
 }
140 140
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 class RegisterControllerCompiler extends AbstractCompiler
12 12
 {
13 13
 	protected $cachePrefix 	= 'register_controller_';
14
-	protected $stubFilename = 'RegisterController.js' ;
14
+	protected $stubFilename = 'RegisterController.js';
15 15
 
16 16
 	public function __construct($scaffolderConfig, $modelData = null)
17 17
 	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
18
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/';
19 19
 		parent::__construct($scaffolderConfig, $modelData);
20 20
 	}
21 21
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 		foreach ($this->modelData->fields as $field)
40 40
 		{
41 41
 
42
-			if($field->type->ui == 'autoComplete' || $field->type->ui == 'multipleAutoComplete')
42
+			if ($field->type->ui == 'autoComplete' || $field->type->ui == 'multipleAutoComplete')
43 43
 			{
44 44
 				$this->stub = str_replace('{{table_from}}', $field->table_from, $this->stub);
45 45
 			}
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 	private function replaceFileUpload()
54 54
 	{
55
-		$fileStub = File::get($this->stubsDirectory . '/Register/FileRegisterControllerStub.php');
55
+		$fileStub = File::get($this->stubsDirectory.'/Register/FileRegisterControllerStub.php');
56 56
 		$this->stub = str_replace('{{file_upload}}', $fileStub, $this->stub);
57 57
 
58 58
 		$keyAutoComplete = $keyMultipleAutoComplete = $keyCheckbox = $keyCheckboxTree = false;
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
 					$keyAutoComplete = true;
68 68
 					break;
69 69
 				case 'multipleAutoComplete':
70
-					$multipleAutoStub = $this->changeStubDataAndTag('MultipleAutoComplete','{{multiple_auto_complete}}',$field->table_from);
70
+					$multipleAutoStub = $this->changeStubDataAndTag('MultipleAutoComplete', '{{multiple_auto_complete}}', $field->table_from);
71 71
 					$keyMultipleAutoComplete = true;
72 72
 					break;
73 73
 				case 'checkbox':
74
-					$checkboxStub = $this->changeStubDataAndTag('Checkbox','{{checkbox}}', $field->table_from);
74
+					$checkboxStub = $this->changeStubDataAndTag('Checkbox', '{{checkbox}}', $field->table_from);
75 75
 					$keyCheckbox = true;
76 76
 					break;
77 77
 				case 'checkboxTree':
78
-					$checkboxTreeStub = $this->changeStubDataAndTag('CheckboxTree','{{checkbox_tree}}', $field->table_from);
78
+					$checkboxTreeStub = $this->changeStubDataAndTag('CheckboxTree', '{{checkbox_tree}}', $field->table_from);
79 79
 					$keyCheckboxTree = true;
80 80
 					break;
81 81
 				default:
82 82
 					break;
83 83
 			}
84 84
 
85
-			if($field->foreignKey)
85
+			if ($field->foreignKey)
86 86
 			{
87 87
 				$this->stub = str_replace('{{foreign_table}}', $field->foreignKey->table, $this->stub);
88 88
 			}
@@ -90,22 +90,22 @@  discard block
 block discarded – undo
90 90
 
91 91
 		}
92 92
 		
93
-		if(!$keyAutoComplete)
93
+		if (!$keyAutoComplete)
94 94
 		{
95 95
 			$this->stub = str_replace('{{auto_complete}}', ' ', $this->stub);
96 96
 		}
97 97
 
98
-		if(!$keyMultipleAutoComplete)
98
+		if (!$keyMultipleAutoComplete)
99 99
 		{
100 100
 			$this->stub = str_replace('{{multiple_auto_complete}}', ' ', $this->stub);
101 101
 		}
102 102
 
103
-		if(!$keyCheckbox)
103
+		if (!$keyCheckbox)
104 104
 		{
105 105
 			$this->stub = str_replace('{{checkbox}}', ' ', $this->stub);
106 106
 		}			
107 107
 
108
-		if(!$keyCheckboxTree)
108
+		if (!$keyCheckboxTree)
109 109
 		{
110 110
 			$this->stub = str_replace('{{checkbox_tree}}', ' ', $this->stub);
111 111
 		}
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 	}
115 115
 	
116 116
 
117
-	public function changeStubDataAndTag($stubName,$stubTag,$table_from)
117
+	public function changeStubDataAndTag($stubName, $stubTag, $table_from)
118 118
 	{
119
-		$stubFile = File::get($this->stubsDirectory . '/Register/'.$stubName.'ControllerStub.php');
119
+		$stubFile = File::get($this->stubsDirectory.'/Register/'.$stubName.'ControllerStub.php');
120 120
 		$stubFile = str_replace('{{table_from}}', $table_from, $stubFile);
121 121
 		$this->stub = str_replace($stubTag, $stubFile, $this->stub);
122 122
 	}
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	protected function getOutputFilename()
131 131
 	{
132
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
132
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/';
133 133
 
134 134
 		Directory::createIfNotExists($folder, 0755, true);
135 135
 
136
-		return $folder .$this->modelData->tableName . '_register.controller.js';
136
+		return $folder.$this->modelData->tableName.'_register.controller.js';
137 137
 	}
138 138
 
139 139
 }
140 140
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/RegisterModuleCompiler.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * Replace and store the Stub.
24 24
 	 *
25
-	 * @return string
25
+	 * @return RegisterModuleCompiler
26 26
 	 */
27 27
 	public function replaceAndStore()
28 28
 	{
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * Get output filename
36 36
 	 *
37 37
 	 *
38
-	 * @return $this
38
+	 * @return string
39 39
 	 */
40 40
 	protected function getOutputFilename()
41 41
 	{
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 
3 3
 namespace Scaffolder\Compilers\AngularJs;
4 4
 
5
-use Illuminate\Support\Facades\File;
6 5
 use Scaffolder\Compilers\AbstractCompiler;
7 6
 use Scaffolder\Compilers\Support\FileToCompile;
8 7
 use Scaffolder\Compilers\Support\PathParser;
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 
11 11
 class RegisterModuleCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'register_module_';
14
-	protected $stubFilename = 'RegisterModule.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
13
+    protected $cachePrefix 	= 'register_module_';
14
+    protected $stubFilename = 'RegisterModule.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29 29
 		
30
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
31 31
 		
32
-	}
32
+    }
33 33
 	
34
-	/**
35
-	 * Get output filename
36
-	 *
37
-	 *
38
-	 * @return $this
39
-	 */
40
-	protected function getOutputFilename()
41
-	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
43
-
44
-		Directory::createIfNotExists($folder, 0755, true);
45
-
46
-		return $folder .$this->modelData->tableName . '_register.module.js';
47
-	}
34
+    /**
35
+     * Get output filename
36
+     *
37
+     *
38
+     * @return $this
39
+     */
40
+    protected function getOutputFilename()
41
+    {
42
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
43
+
44
+        Directory::createIfNotExists($folder, 0755, true);
45
+
46
+        return $folder .$this->modelData->tableName . '_register.module.js';
47
+    }
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 class RegisterModuleCompiler extends AbstractCompiler
12 12
 {
13 13
 	protected $cachePrefix 	= 'register_module_';
14
-	protected $stubFilename = 'RegisterModule.js' ;
14
+	protected $stubFilename = 'RegisterModule.js';
15 15
 
16 16
 	public function __construct($scaffolderConfig, $modelData = null)
17 17
 	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
18
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/';
19 19
 		parent::__construct($scaffolderConfig, $modelData);
20 20
 	}
21 21
 
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	protected function getOutputFilename()
41 41
 	{
42
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
42
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/';
43 43
 
44 44
 		Directory::createIfNotExists($folder, 0755, true);
45 45
 
46
-		return $folder .$this->modelData->tableName . '_register.module.js';
46
+		return $folder.$this->modelData->tableName.'_register.module.js';
47 47
 	}
48 48
 
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/RegisterTemplateCompiler.php 5 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	/**
26 26
 	 * Replace and store the Stub.
27 27
 	 *
28
-	 * @return string
28
+	 * @return RegisterTemplateCompiler
29 29
 	 */
30 30
 	public function replaceAndStore()
31 31
 	{
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * get search conditions
56 56
 	 *
57
-	 * @return $this
57
+	 * @return string
58 58
 	 */
59 59
 	public function getInputFields(){
60 60
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @param string $field
129 129
 	 * @param string $fieldStub
130 130
 	 *
131
-	 * @return $this
131
+	 * @return string
132 132
 	 */
133 133
 	protected function replaceFieldInput($field, $fieldStub){
134 134
 		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @param string $field
144 144
 	 * @param string $fieldStub
145 145
 	 *
146
-	 * @return $this
146
+	 * @return string
147 147
 	 */
148 148
 	protected function replaceFieldValidations($field, $fieldStub){
149 149
 		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 	 * Get output filename
203 203
 	 *
204 204
 	 *
205
-	 * @return $this
205
+	 * @return string
206 206
 	 */
207 207
 	protected function getOutputFilename()
208 208
 	{
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@
 block discarded – undo
9 9
 use Scaffolder\Support\Directory;
10 10
 use Scaffolder\Support\CamelCase;
11 11
 use Scaffolder\Support\Validator;
12
-use stdClass ;
13 12
 
14 13
 class RegisterTemplateCompiler extends AbstractCompiler
15 14
 {
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -13,204 +13,204 @@
 block discarded – undo
13 13
 
14 14
 class RegisterTemplateCompiler extends AbstractCompiler
15 15
 {
16
-	protected $cachePrefix 	= 'register_template_';
17
-	protected $stubFilename = 'RegisterTemplate.html' ;
18
-
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
-		parent::__construct($scaffolderConfig, $modelData);
23
-	}
24
-
25
-	/**
26
-	 * Replace and store the Stub.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function replaceAndStore()
31
-	{
16
+    protected $cachePrefix 	= 'register_template_';
17
+    protected $stubFilename = 'RegisterTemplate.html' ;
18
+
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
+        parent::__construct($scaffolderConfig, $modelData);
23
+    }
24
+
25
+    /**
26
+     * Replace and store the Stub.
27
+     *
28
+     * @return string
29
+     */
30
+    public function replaceAndStore()
31
+    {
32 32
 		
33
-		return $this
34
-				->replaceInputFields()
35
-				->replaceBelongsToManyFields()
36
-				->store(new FileToCompile(false, $this->modelData->modelHash));
33
+        return $this
34
+                ->replaceInputFields()
35
+                ->replaceBelongsToManyFields()
36
+                ->store(new FileToCompile(false, $this->modelData->modelHash));
37 37
 		
38
-	}
38
+    }
39 39
 
40
-	/**
41
-	 * Replace input fields
42
-	 *
43
-	 * @return $this
44
-	 */
45
-	private function replaceInputFields(){
40
+    /**
41
+     * Replace input fields
42
+     *
43
+     * @return $this
44
+     */
45
+    private function replaceInputFields(){
46 46
 
47
-		$inputFields = $this->getInputFields();
47
+        $inputFields = $this->getInputFields();
48 48
 
49
-		$this->stub = str_replace('{{columns_inputs}}', $inputFields, $this->stub);
49
+        $this->stub = str_replace('{{columns_inputs}}', $inputFields, $this->stub);
50 50
 
51
-		return $this;
52
-	}
51
+        return $this;
52
+    }
53 53
 
54
-	/**
55
-	 * get search conditions
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	public function getInputFields(){
54
+    /**
55
+     * get search conditions
56
+     *
57
+     * @return $this
58
+     */
59
+    public function getInputFields(){
60 60
 
61
-		$inputFields = $eagerFields = '';
61
+        $inputFields = $eagerFields = '';
62 62
 
63
-		foreach ($this->modelData->fields as $field)
64
-		{
65
-			$fieldStub = $this->getInputStubByField($field);
63
+        foreach ($this->modelData->fields as $field)
64
+        {
65
+            $fieldStub = $this->getInputStubByField($field);
66 66
 			
67
-			if($field->foreignKey){
67
+            if($field->foreignKey){
68 68
 				
69
-				$fieldStub 	= $this->replaceForeingStrings($field, $fieldStub) ;
70
-				$fieldStub = str_replace('{{foreign_model_name}}', strtolower(CamelCase::convertToCamelCase($field->foreignKey->table)), $fieldStub);
71
-			}
72
-
73
-			$inputFields .= $this->replaceFieldInput($field, $fieldStub) ;
74
-
75
-			// Check foreign key
76
-			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
77
-			{
78
-				// search eager fields
79
-				$foreignModelData = $this->getModelData($field->foreignKey->table);
80
-				$foreignControllerCompiler = new RegisterTemplateCompiler($this->scaffolderConfig, $foreignModelData);
81
-				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
82
-				$eagerFields 	.= $foreignControllerCompiler->getInputFields();
83
-			}
84
-
85
-		}
86
-
87
-		// replace table name
88
-		$inputFields = str_replace('{{table_name}}', $this->modelData->tableName, $inputFields);
69
+                $fieldStub 	= $this->replaceForeingStrings($field, $fieldStub) ;
70
+                $fieldStub = str_replace('{{foreign_model_name}}', strtolower(CamelCase::convertToCamelCase($field->foreignKey->table)), $fieldStub);
71
+            }
72
+
73
+            $inputFields .= $this->replaceFieldInput($field, $fieldStub) ;
74
+
75
+            // Check foreign key
76
+            if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
77
+            {
78
+                // search eager fields
79
+                $foreignModelData = $this->getModelData($field->foreignKey->table);
80
+                $foreignControllerCompiler = new RegisterTemplateCompiler($this->scaffolderConfig, $foreignModelData);
81
+                $foreignControllerCompiler->setEagerTable($this->modelData->tableName);
82
+                $eagerFields 	.= $foreignControllerCompiler->getInputFields();
83
+            }
84
+
85
+        }
86
+
87
+        // replace table name
88
+        $inputFields = str_replace('{{table_name}}', $this->modelData->tableName, $inputFields);
89 89
 		
90
-		$this->stub = str_replace('{{eager_objects_inputs}}', $eagerFields, $this->stub); 
90
+        $this->stub = str_replace('{{eager_objects_inputs}}', $eagerFields, $this->stub); 
91 91
 
92
-		return $inputFields ;
92
+        return $inputFields ;
93 93
 
94
-	}
94
+    }
95 95
 
96
-	/**
97
-	 * Replace belongs to many fields
98
-	 *
99
-	 * @return $this
100
-	 */
101
-	protected function replaceBelongsToManyFields() {
96
+    /**
97
+     * Replace belongs to many fields
98
+     *
99
+     * @return $this
100
+     */
101
+    protected function replaceBelongsToManyFields() {
102 102
 		
103
-		$belongToManyFields = '';
103
+        $belongToManyFields = '';
104 104
 		
105
-		foreach ($this->modelData->reverseRelationships as $relationship)
106
-		{
107
-			if ($relationship->type == "belongsToMany") {
108
-				$fieldStub = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($relationship->ui). '.html');
109
-
110
-				$fieldStub = str_replace('{{related_table}}',CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
111
-				$fieldStub = str_replace('{{related_table_lw}}', strtolower(CamelCase::convertToCamelCase($relationship->relatedTable)), $fieldStub);
112
-				$fieldStub = str_replace('{{table_name}}', $this->modelData->tableName, $fieldStub);
113
-				$fieldStub = str_replace('{{related_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $fieldStub);
114
-				$fieldStub = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $fieldStub);
105
+        foreach ($this->modelData->reverseRelationships as $relationship)
106
+        {
107
+            if ($relationship->type == "belongsToMany") {
108
+                $fieldStub = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($relationship->ui). '.html');
109
+
110
+                $fieldStub = str_replace('{{related_table}}',CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
111
+                $fieldStub = str_replace('{{related_table_lw}}', strtolower(CamelCase::convertToCamelCase($relationship->relatedTable)), $fieldStub);
112
+                $fieldStub = str_replace('{{table_name}}', $this->modelData->tableName, $fieldStub);
113
+                $fieldStub = str_replace('{{related_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $fieldStub);
114
+                $fieldStub = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $fieldStub);
115 115
 				
116
-				$belongToManyFields .= $fieldStub;	
117
-			}
118
-		}
116
+                $belongToManyFields .= $fieldStub;	
117
+            }
118
+        }
119 119
 
120
-		$this->stub = str_replace('{{belongs_to_many_inputs}}', $belongToManyFields, $this->stub); 
120
+        $this->stub = str_replace('{{belongs_to_many_inputs}}', $belongToManyFields, $this->stub); 
121 121
 
122
-		return $this;
123
-	}
122
+        return $this;
123
+    }
124 124
 	
125
-	/**
126
-	 * replace field stub with fields and validations
127
-	 *
128
-	 * @param string $field
129
-	 * @param string $fieldStub
130
-	 *
131
-	 * @return $this
132
-	 */
133
-	protected function replaceFieldInput($field, $fieldStub){
134
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
135
-		$fieldStub = $this->replaceFieldValidations($field, $fieldStub) ;
136
-
137
-		return $fieldStub ;
138
-	}
139
-
140
-	/**
141
-	 * replace field stub with fields and validations
142
-	 *
143
-	 * @param string $field
144
-	 * @param string $fieldStub
145
-	 *
146
-	 * @return $this
147
-	 */
148
-	protected function replaceFieldValidations($field, $fieldStub){
149
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
125
+    /**
126
+     * replace field stub with fields and validations
127
+     *
128
+     * @param string $field
129
+     * @param string $fieldStub
130
+     *
131
+     * @return $this
132
+     */
133
+    protected function replaceFieldInput($field, $fieldStub){
134
+        $fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
135
+        $fieldStub = $this->replaceFieldValidations($field, $fieldStub) ;
136
+
137
+        return $fieldStub ;
138
+    }
139
+
140
+    /**
141
+     * replace field stub with fields and validations
142
+     *
143
+     * @param string $field
144
+     * @param string $fieldStub
145
+     *
146
+     * @return $this
147
+     */
148
+    protected function replaceFieldValidations($field, $fieldStub){
149
+        $fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
150 150
 		
151
-		$validationsConverted = Validator::convertValidations($field->validations);
151
+        $validationsConverted = Validator::convertValidations($field->validations);
152 152
 
153
-		$inputValidations = '' ; 
153
+        $inputValidations = '' ; 
154 154
 
155
-		foreach ($validationsConverted as $attribute => $value) {
156
-			if($value)
157
-				$inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
-			else
159
-				$inputValidations .=  ' '.$attribute  ; 
160
-		}
155
+        foreach ($validationsConverted as $attribute => $value) {
156
+            if($value)
157
+                $inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
+            else
159
+                $inputValidations .=  ' '.$attribute  ; 
160
+        }
161 161
 
162
-		$fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
162
+        $fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
163 163
 
164
-		return $fieldStub ;
165
-	}
164
+        return $fieldStub ;
165
+    }
166 166
 
167 167
 	
168
-	/**
169
-	 * get input field stub by ui type
170
-	 *
171
-	 * @param string $field
172
-	 *
173
-	 * @return $this
174
-	 */
175
-	private $inputStub = [];
176
-	private function getInputStubByField($field){
168
+    /**
169
+     * get input field stub by ui type
170
+     *
171
+     * @param string $field
172
+     *
173
+     * @return $this
174
+     */
175
+    private $inputStub = [];
176
+    private function getInputStubByField($field){
177 177
 		
178
-		if($field->index == 'primary'){
179
-			$uiType = 'primary' ;
180
-		}
181
-		elseif(isset($field->foreignKey) && $field->foreignKey){
182
-			if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
-				$uiType = 'foreign_eager' ;
184
-			else 
185
-				$uiType = $field->type->ui ;
186
-		}
187
-		else {
188
-			$uiType = $field->type->ui ;
189
-		}
190
-
191
-		if(array_key_exists($uiType, $this->inputStub)){
192
-			return $this->inputStub[$uiType];
193
-		}
194
-		else {
195
-			$this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
196
-
197
-			return $this->inputStub[$uiType];
198
-		}
199
-	}
200
-
201
-	/**
202
-	 * Get output filename
203
-	 *
204
-	 *
205
-	 * @return $this
206
-	 */
207
-	protected function getOutputFilename()
208
-	{
209
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
210
-
211
-		Directory::createIfNotExists($folder, 0755, true);
212
-
213
-		return $folder .$this->modelData->tableName . '_register.html';
214
-	}
178
+        if($field->index == 'primary'){
179
+            $uiType = 'primary' ;
180
+        }
181
+        elseif(isset($field->foreignKey) && $field->foreignKey){
182
+            if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
+                $uiType = 'foreign_eager' ;
184
+            else 
185
+                $uiType = $field->type->ui ;
186
+        }
187
+        else {
188
+            $uiType = $field->type->ui ;
189
+        }
190
+
191
+        if(array_key_exists($uiType, $this->inputStub)){
192
+            return $this->inputStub[$uiType];
193
+        }
194
+        else {
195
+            $this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
196
+
197
+            return $this->inputStub[$uiType];
198
+        }
199
+    }
200
+
201
+    /**
202
+     * Get output filename
203
+     *
204
+     *
205
+     * @return $this
206
+     */
207
+    protected function getOutputFilename()
208
+    {
209
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
210
+
211
+        Directory::createIfNotExists($folder, 0755, true);
212
+
213
+        return $folder .$this->modelData->tableName . '_register.html';
214
+    }
215 215
 
216 216
 }
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@  discard block
 block discarded – undo
9 9
 use Scaffolder\Support\Directory;
10 10
 use Scaffolder\Support\CamelCase;
11 11
 use Scaffolder\Support\Validator;
12
-use stdClass ;
12
+use stdClass;
13 13
 
14 14
 class RegisterTemplateCompiler extends AbstractCompiler
15 15
 {
16 16
 	protected $cachePrefix 	= 'register_template_';
17
-	protected $stubFilename = 'RegisterTemplate.html' ;
17
+	protected $stubFilename = 'RegisterTemplate.html';
18 18
 
19 19
 	public function __construct($scaffolderConfig, $modelData = null)
20 20
 	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
21
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/';
22 22
 		parent::__construct($scaffolderConfig, $modelData);
23 23
 	}
24 24
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return $this
44 44
 	 */
45
-	private function replaceInputFields(){
45
+	private function replaceInputFields() {
46 46
 
47 47
 		$inputFields = $this->getInputFields();
48 48
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @return $this
58 58
 	 */
59
-	public function getInputFields(){
59
+	public function getInputFields() {
60 60
 
61 61
 		$inputFields = $eagerFields = '';
62 62
 
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 		{
65 65
 			$fieldStub = $this->getInputStubByField($field);
66 66
 			
67
-			if($field->foreignKey){
67
+			if ($field->foreignKey) {
68 68
 				
69
-				$fieldStub 	= $this->replaceForeingStrings($field, $fieldStub) ;
69
+				$fieldStub = $this->replaceForeingStrings($field, $fieldStub);
70 70
 				$fieldStub = str_replace('{{foreign_model_name}}', strtolower(CamelCase::convertToCamelCase($field->foreignKey->table)), $fieldStub);
71 71
 			}
72 72
 
73
-			$inputFields .= $this->replaceFieldInput($field, $fieldStub) ;
73
+			$inputFields .= $this->replaceFieldInput($field, $fieldStub);
74 74
 
75 75
 			// Check foreign key
76 76
 			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 				$foreignModelData = $this->getModelData($field->foreignKey->table);
80 80
 				$foreignControllerCompiler = new RegisterTemplateCompiler($this->scaffolderConfig, $foreignModelData);
81 81
 				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
82
-				$eagerFields 	.= $foreignControllerCompiler->getInputFields();
82
+				$eagerFields .= $foreignControllerCompiler->getInputFields();
83 83
 			}
84 84
 
85 85
 		}
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		
90 90
 		$this->stub = str_replace('{{eager_objects_inputs}}', $eagerFields, $this->stub); 
91 91
 
92
-		return $inputFields ;
92
+		return $inputFields;
93 93
 
94 94
 	}
95 95
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
 		foreach ($this->modelData->reverseRelationships as $relationship)
106 106
 		{
107 107
 			if ($relationship->type == "belongsToMany") {
108
-				$fieldStub = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($relationship->ui). '.html');
108
+				$fieldStub = File::get($this->stubsDirectory.'Register/'.CamelCase::convertToCamelCase($relationship->ui).'.html');
109 109
 
110
-				$fieldStub = str_replace('{{related_table}}',CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
110
+				$fieldStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $fieldStub);
111 111
 				$fieldStub = str_replace('{{related_table_lw}}', strtolower(CamelCase::convertToCamelCase($relationship->relatedTable)), $fieldStub);
112 112
 				$fieldStub = str_replace('{{table_name}}', $this->modelData->tableName, $fieldStub);
113 113
 				$fieldStub = str_replace('{{related_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $fieldStub);
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @return $this
132 132
 	 */
133
-	protected function replaceFieldInput($field, $fieldStub){
134
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
135
-		$fieldStub = $this->replaceFieldValidations($field, $fieldStub) ;
133
+	protected function replaceFieldInput($field, $fieldStub) {
134
+		$fieldStub = $this->replaceFieldStrings($field, $fieldStub);
135
+		$fieldStub = $this->replaceFieldValidations($field, $fieldStub);
136 136
 
137
-		return $fieldStub ;
137
+		return $fieldStub;
138 138
 	}
139 139
 
140 140
 	/**
@@ -145,23 +145,23 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @return $this
147 147
 	 */
148
-	protected function replaceFieldValidations($field, $fieldStub){
149
-		$fieldStub = $this->replaceFieldStrings($field, $fieldStub) ;
148
+	protected function replaceFieldValidations($field, $fieldStub) {
149
+		$fieldStub = $this->replaceFieldStrings($field, $fieldStub);
150 150
 		
151 151
 		$validationsConverted = Validator::convertValidations($field->validations);
152 152
 
153
-		$inputValidations = '' ; 
153
+		$inputValidations = ''; 
154 154
 
155 155
 		foreach ($validationsConverted as $attribute => $value) {
156
-			if($value)
157
-				$inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
156
+			if ($value)
157
+				$inputValidations .= ' '.$attribute.'="'.$value.'"';
158 158
 			else
159
-				$inputValidations .=  ' '.$attribute  ; 
159
+				$inputValidations .= ' '.$attribute; 
160 160
 		}
161 161
 
162 162
 		$fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
163 163
 
164
-		return $fieldStub ;
164
+		return $fieldStub;
165 165
 	}
166 166
 
167 167
 	
@@ -173,26 +173,26 @@  discard block
 block discarded – undo
173 173
 	 * @return $this
174 174
 	 */
175 175
 	private $inputStub = [];
176
-	private function getInputStubByField($field){
176
+	private function getInputStubByField($field) {
177 177
 		
178
-		if($field->index == 'primary'){
179
-			$uiType = 'primary' ;
178
+		if ($field->index == 'primary') {
179
+			$uiType = 'primary';
180 180
 		}
181
-		elseif(isset($field->foreignKey) && $field->foreignKey){
182
-			if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
-				$uiType = 'foreign_eager' ;
181
+		elseif (isset($field->foreignKey) && $field->foreignKey) {
182
+			if (isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
+				$uiType = 'foreign_eager';
184 184
 			else 
185
-				$uiType = $field->type->ui ;
185
+				$uiType = $field->type->ui;
186 186
 		}
187 187
 		else {
188
-			$uiType = $field->type->ui ;
188
+			$uiType = $field->type->ui;
189 189
 		}
190 190
 
191
-		if(array_key_exists($uiType, $this->inputStub)){
191
+		if (array_key_exists($uiType, $this->inputStub)) {
192 192
 			return $this->inputStub[$uiType];
193 193
 		}
194 194
 		else {
195
-			$this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
195
+			$this->inputStub[$uiType] = File::get($this->stubsDirectory.'Register/'.CamelCase::convertToCamelCase($uiType).'.html');
196 196
 
197 197
 			return $this->inputStub[$uiType];
198 198
 		}
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 	 */
207 207
 	protected function getOutputFilename()
208 208
 	{
209
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/' ;
209
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/register/';
210 210
 
211 211
 		Directory::createIfNotExists($folder, 0755, true);
212 212
 
213
-		return $folder .$this->modelData->tableName . '_register.html';
213
+		return $folder.$this->modelData->tableName.'_register.html';
214 214
 	}
215 215
 
216 216
 }
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -153,10 +153,11 @@  discard block
 block discarded – undo
153 153
 		$inputValidations = '' ; 
154 154
 
155 155
 		foreach ($validationsConverted as $attribute => $value) {
156
-			if($value)
157
-				$inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
-			else
159
-				$inputValidations .=  ' '.$attribute  ; 
156
+			if($value) {
157
+							$inputValidations .=  ' '.$attribute.'="'. $value.'"' ;
158
+			} else {
159
+							$inputValidations .=  ' '.$attribute  ;
160
+			}
160 161
 		}
161 162
 
162 163
 		$fieldStub = str_replace('{{field_validation}}', $inputValidations, $fieldStub);
@@ -177,21 +178,19 @@  discard block
 block discarded – undo
177 178
 		
178 179
 		if($field->index == 'primary'){
179 180
 			$uiType = 'primary' ;
180
-		}
181
-		elseif(isset($field->foreignKey) && $field->foreignKey){
182
-			if(isset($field->foreignKey->eager) && $field->foreignKey->eager)
183
-				$uiType = 'foreign_eager' ;
184
-			else 
185
-				$uiType = $field->type->ui ;
186
-		}
187
-		else {
181
+		} elseif(isset($field->foreignKey) && $field->foreignKey){
182
+			if(isset($field->foreignKey->eager) && $field->foreignKey->eager) {
183
+							$uiType = 'foreign_eager' ;
184
+			} else {
185
+							$uiType = $field->type->ui ;
186
+			}
187
+		} else {
188 188
 			$uiType = $field->type->ui ;
189 189
 		}
190 190
 
191 191
 		if(array_key_exists($uiType, $this->inputStub)){
192 192
 			return $this->inputStub[$uiType];
193
-		}
194
-		else {
193
+		} else {
195 194
 			$this->inputStub[$uiType] = File::get($this->stubsDirectory . 'Register/'. CamelCase::convertToCamelCase($uiType). '.html');
196 195
 
197 196
 			return $this->inputStub[$uiType];
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/ResourceCompiler.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * Replace and store the Stub.
24 24
 	 *
25
-	 * @return string
25
+	 * @return ResourceCompiler
26 26
 	 */
27 27
 	public function replaceAndStore()
28 28
 	{
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * Get output filename
34 34
 	 *
35 35
 	 *
36
-	 * @return $this
36
+	 * @return string
37 37
 	 */
38 38
 	protected function getOutputFilename()
39 39
 	{
Please login to merge, or discard this patch.
Unused Use Statements   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,9 +2,8 @@
 block discarded – undo
2 2
 
3 3
 namespace Scaffolder\Compilers\AngularJs;
4 4
 
5
-use Illuminate\Support\Facades\File;
6 5
 use Scaffolder\Compilers\AbstractCompiler;
7
-use Scaffolder\Compilers\Support\FileToCompile; 
6
+use Scaffolder\Compilers\Support\FileToCompile;
8 7
 use Scaffolder\Compilers\Support\PathParser;
9 8
 use Scaffolder\Support\Directory;
10 9
 
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,38 +10,38 @@
 block discarded – undo
10 10
 
11 11
 class ResourceCompiler extends AbstractCompiler
12 12
 {
13
-	protected $cachePrefix 	= 'resource_';
14
-	protected $stubFilename = 'Resource.js' ;
15
-
16
-	public function __construct($scaffolderConfig, $modelData = null)
17
-	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
-		parent::__construct($scaffolderConfig, $modelData);
20
-	}
21
-
22
-	/**
23
-	 * Replace and store the Stub.
24
-	 *
25
-	 * @return string
26
-	 */
27
-	public function replaceAndStore()
28
-	{
29
-		return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
-	}
13
+    protected $cachePrefix 	= 'resource_';
14
+    protected $stubFilename = 'Resource.js' ;
15
+
16
+    public function __construct($scaffolderConfig, $modelData = null)
17
+    {
18
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
19
+        parent::__construct($scaffolderConfig, $modelData);
20
+    }
21
+
22
+    /**
23
+     * Replace and store the Stub.
24
+     *
25
+     * @return string
26
+     */
27
+    public function replaceAndStore()
28
+    {
29
+        return $this->store(new FileToCompile(false, $this->modelData->modelHash));
30
+    }
31 31
 	
32
-	/**
33
-	 * Get output filename
34
-	 *
35
-	 *
36
-	 * @return $this
37
-	 */
38
-	protected function getOutputFilename()
39
-	{
40
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/' ;
41
-
42
-		Directory::createIfNotExists($folder, 0755, true);
43
-
44
-		return $folder .  $this->modelData->tableName . '.resource.js';
45
-	}
32
+    /**
33
+     * Get output filename
34
+     *
35
+     *
36
+     * @return $this
37
+     */
38
+    protected function getOutputFilename()
39
+    {
40
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/' ;
41
+
42
+        Directory::createIfNotExists($folder, 0755, true);
43
+
44
+        return $folder .  $this->modelData->tableName . '.resource.js';
45
+    }
46 46
 
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
 class ResourceCompiler extends AbstractCompiler
12 12
 {
13 13
 	protected $cachePrefix 	= 'resource_';
14
-	protected $stubFilename = 'Resource.js' ;
14
+	protected $stubFilename = 'Resource.js';
15 15
 
16 16
 	public function __construct($scaffolderConfig, $modelData = null)
17 17
 	{
18
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
18
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/';
19 19
 		parent::__construct($scaffolderConfig, $modelData);
20 20
 	}
21 21
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	protected function getOutputFilename()
39 39
 	{
40
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/' ;
40
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/';
41 41
 
42 42
 		Directory::createIfNotExists($folder, 0755, true);
43 43
 
44
-		return $folder .  $this->modelData->tableName . '.resource.js';
44
+		return $folder.$this->modelData->tableName.'.resource.js';
45 45
 	}
46 46
 
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/AngularJs/TranslateCompiler.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	/**
26 26
 	 * Replace and store the Stub.
27 27
 	 *
28
-	 * @return string
28
+	 * @return TranslateCompiler
29 29
 	 */
30 30
 	public function replaceAndStore()
31 31
 	{
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * Get output filename
72 72
 	 *
73 73
 	 *
74
-	 * @return $this
74
+	 * @return string
75 75
 	 */
76 76
 	protected function getOutputFilename()
77 77
 	{
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,13 +2,11 @@
 block discarded – undo
2 2
 
3 3
 namespace Scaffolder\Compilers\AngularJs;
4 4
 
5
-use Illuminate\Support\Facades\File;
6 5
 use Scaffolder\Compilers\AbstractCompiler;
7 6
 use Scaffolder\Compilers\Support\FileToCompile;
8 7
 use Scaffolder\Compilers\Support\PathParser;
9 8
 use Scaffolder\Support\Directory;
10 9
 use Scaffolder\Support\CamelCase;
11
-use stdClass ;
12 10
 
13 11
 
14 12
 class TranslateCompiler extends AbstractCompiler
Please login to merge, or discard this patch.
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -13,73 +13,73 @@
 block discarded – undo
13 13
 
14 14
 class TranslateCompiler extends AbstractCompiler
15 15
 {
16
-	protected $cachePrefix 	= 'translate_';
17
-	protected $stubFilename = 'Translate.js' ;
18
-
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
-		parent::__construct($scaffolderConfig, $modelData);
23
-	}
24
-
25
-	/**
26
-	 * Replace and store the Stub.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function replaceAndStore()
31
-	{
16
+    protected $cachePrefix 	= 'translate_';
17
+    protected $stubFilename = 'Translate.js' ;
18
+
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
22
+        parent::__construct($scaffolderConfig, $modelData);
23
+    }
24
+
25
+    /**
26
+     * Replace and store the Stub.
27
+     *
28
+     * @return string
29
+     */
30
+    public function replaceAndStore()
31
+    {
32 32
 		
33
-		return $this->replaceColumns()
34
-					->replaceArea()
35
-					->store(new FileToCompile(false, $this->modelData->modelHash));
33
+        return $this->replaceColumns()
34
+                    ->replaceArea()
35
+                    ->store(new FileToCompile(false, $this->modelData->modelHash));
36 36
 		
37
-	}
38
-
39
-	/**
40
-	 * replace columns
41
-	 *
42
-	 * @return $this
43
-	 */
44
-	public function replaceArea(){
45
-		$this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); 
46
-		$this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); 
47
-		return $this;
48
-	}
49
-
50
-	/**
51
-	 * replace columns
52
-	 *
53
-	 * @return $this
54
-	 */
55
-	public function replaceColumns(){
56
-
57
-		$columns = [];
58
-
59
-		foreach ($this->modelData->fields as $field)
60
-		{
61
-			array_push($columns,  "\t\t".sprintf('"%s" : "%s"',  $field->name,  CamelCase::convertToCamelCase($field->name) ));
62
-		}
63
-
64
-		$this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); 
65
-
66
-		return $this ;
67
-
68
-	}
37
+    }
38
+
39
+    /**
40
+     * replace columns
41
+     *
42
+     * @return $this
43
+     */
44
+    public function replaceArea(){
45
+        $this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); 
46
+        $this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); 
47
+        return $this;
48
+    }
49
+
50
+    /**
51
+     * replace columns
52
+     *
53
+     * @return $this
54
+     */
55
+    public function replaceColumns(){
56
+
57
+        $columns = [];
58
+
59
+        foreach ($this->modelData->fields as $field)
60
+        {
61
+            array_push($columns,  "\t\t".sprintf('"%s" : "%s"',  $field->name,  CamelCase::convertToCamelCase($field->name) ));
62
+        }
63
+
64
+        $this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); 
65
+
66
+        return $this ;
67
+
68
+    }
69 69
 	
70
-	/**
71
-	 * Get output filename
72
-	 *
73
-	 *
74
-	 * @return $this
75
-	 */
76
-	protected function getOutputFilename()
77
-	{
78
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ;
79
-
80
-		Directory::createIfNotExists($folder, 0755, true);
81
-
82
-		return $folder . 'en.json';
83
-	}
70
+    /**
71
+     * Get output filename
72
+     *
73
+     *
74
+     * @return $this
75
+     */
76
+    protected function getOutputFilename()
77
+    {
78
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ;
79
+
80
+        Directory::createIfNotExists($folder, 0755, true);
81
+
82
+        return $folder . 'en.json';
83
+    }
84 84
 
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,17 +8,17 @@  discard block
 block discarded – undo
8 8
 use Scaffolder\Compilers\Support\PathParser;
9 9
 use Scaffolder\Support\Directory;
10 10
 use Scaffolder\Support\CamelCase;
11
-use stdClass ;
11
+use stdClass;
12 12
 
13 13
 
14 14
 class TranslateCompiler extends AbstractCompiler
15 15
 {
16 16
 	protected $cachePrefix 	= 'translate_';
17
-	protected $stubFilename = 'Translate.js' ;
17
+	protected $stubFilename = 'Translate.js';
18 18
 
19 19
 	public function __construct($scaffolderConfig, $modelData = null)
20 20
 	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/';
21
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/AngularJs/';
22 22
 		parent::__construct($scaffolderConfig, $modelData);
23 23
 	}
24 24
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @return $this
43 43
 	 */
44
-	public function replaceArea(){
44
+	public function replaceArea() {
45 45
 		$this->stub = str_replace('{{singular}}', ucwords($this->modelData->tableName), $this->stub); 
46 46
 		$this->stub = str_replace('{{plural}}', ucwords(CamelCase::pluralize($this->modelData->tableName)), $this->stub); 
47 47
 		return $this;
@@ -52,18 +52,18 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @return $this
54 54
 	 */
55
-	public function replaceColumns(){
55
+	public function replaceColumns() {
56 56
 
57 57
 		$columns = [];
58 58
 
59 59
 		foreach ($this->modelData->fields as $field)
60 60
 		{
61
-			array_push($columns,  "\t\t".sprintf('"%s" : "%s"',  $field->name,  CamelCase::convertToCamelCase($field->name) ));
61
+			array_push($columns, "\t\t".sprintf('"%s" : "%s"', $field->name, CamelCase::convertToCamelCase($field->name)));
62 62
 		}
63 63
 
64 64
 		$this->stub = str_replace('{{columns}}', join(",\n", $columns), $this->stub); 
65 65
 
66
-		return $this ;
66
+		return $this;
67 67
 
68 68
 	}
69 69
 	
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	protected function getOutputFilename()
77 77
 	{
78
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/' ;
78
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->pages).$this->modelData->tableName.'/i18n/';
79 79
 
80 80
 		Directory::createIfNotExists($folder, 0755, true);
81 81
 
82
-		return $folder . 'en.json';
82
+		return $folder.'en.json';
83 83
 	}
84 84
 
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/ControllerCompiler.php 4 patches
Doc Comments   +9 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,6 +13,9 @@  discard block
 block discarded – undo
13 13
 	protected $cachePrefix 	= 'controller_';
14 14
 	protected $stubFilename = 'Controller/Controller.php' ;
15 15
 	
16
+	/**
17
+	 * @param string $stubName
18
+	 */
16 19
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
17 20
 	{
18 21
 		if ($stubName)
@@ -24,7 +27,7 @@  discard block
 block discarded – undo
24 27
 	/**
25 28
 	 * Replace and store the Stub.
26 29
 	 *
27
-	 * @return string
30
+	 * @return ControllerCompiler
28 31
 	 */
29 32
 	public function replaceAndStore()
30 33
 	{
@@ -49,7 +52,7 @@  discard block
 block discarded – undo
49 52
 	 * Get output filename
50 53
 	 *
51 54
 	 *
52
-	 * @return $this
55
+	 * @return string
53 56
 	 */
54 57
 	protected function getOutputFilename()
55 58
 	{
@@ -474,6 +477,10 @@  discard block
 block discarded – undo
474 477
 	 * @return $this
475 478
 	 */
476 479
 	private $conditionsStub = [];
480
+
481
+	/**
482
+	 * @return string
483
+	 */
477 484
 	private function getConditionStubByField($field){
478 485
 		
479 486
 		if($field->index == 'primary'){
Please login to merge, or discard this patch.
Indentation   +402 added lines, -402 removed lines patch added patch discarded remove patch
@@ -10,437 +10,437 @@  discard block
 block discarded – undo
10 10
 
11 11
 class ControllerCompiler extends AbstractCompiler
12 12
 {	
13
-	protected $cachePrefix 	= 'controller_';
14
-	protected $stubFilename = 'Controller/Controller.php' ;
13
+    protected $cachePrefix 	= 'controller_';
14
+    protected $stubFilename = 'Controller/Controller.php' ;
15 15
 	
16
-	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
17
-	{
18
-		if ($stubName)
19
-			$this->stubFilename = $stubName;
20
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21
-		parent::__construct($scaffolderConfig, $modelData);
22
-	}
23
-
24
-	/**
25
-	 * Replace and store the Stub.
26
-	 *
27
-	 * @return string
28
-	 */
29
-	public function replaceAndStore()
30
-	{
16
+    public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
17
+    {
18
+        if ($stubName)
19
+            $this->stubFilename = $stubName;
20
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21
+        parent::__construct($scaffolderConfig, $modelData);
22
+    }
23
+
24
+    /**
25
+     * Replace and store the Stub.
26
+     *
27
+     * @return string
28
+     */
29
+    public function replaceAndStore()
30
+    {
31 31
 		
32
-		return $this->replacePrimaryKey()
33
-					->replaceEagerCode()
34
-					->replaceUniqueRules()
35
-					->replaceSearchConditions()
36
-					->replaceSimpleFilter()
37
-					->replaceSortConditions()
38
-					->replaceRoutePrefix()
39
-					->replaceReverseRelationships()
40
-					->replaceCheckbox()
41
-					->replaceEnum()
42
-					->replaceRelationshipTables()
43
-					->store(new FileToCompile(false, $this->modelData->modelHash));
32
+        return $this->replacePrimaryKey()
33
+                    ->replaceEagerCode()
34
+                    ->replaceUniqueRules()
35
+                    ->replaceSearchConditions()
36
+                    ->replaceSimpleFilter()
37
+                    ->replaceSortConditions()
38
+                    ->replaceRoutePrefix()
39
+                    ->replaceReverseRelationships()
40
+                    ->replaceCheckbox()
41
+                    ->replaceEnum()
42
+                    ->replaceRelationshipTables()
43
+                    ->store(new FileToCompile(false, $this->modelData->modelHash));
44 44
 		
45
-	}
46
-
47
-
48
-	/**
49
-	 * Get output filename
50
-	 *
51
-	 *
52
-	 * @return $this
53
-	 */
54
-	protected function getOutputFilename()
55
-	{
56
-
57
-		return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php';
58
-	}
59
-
60
-	/**
61
-	 * Replace eager code for each foreing key with eager = true 
62
-	 *
63
-	 * @return $this
64
-	 */
65
-	private function replaceEagerCode()
66
-	{
67
-		$storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
68
-		$eagerConditions = $eagerJoins = '';
69
-
70
-		$storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
71
-		$updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
72
-		$rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
73
-		$useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
74
-		$joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
75
-
76
-		foreach ($this->modelData->fields as $field)
77
-		{
45
+    }
46
+
47
+
48
+    /**
49
+     * Get output filename
50
+     *
51
+     *
52
+     * @return $this
53
+     */
54
+    protected function getOutputFilename()
55
+    {
56
+
57
+        return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php';
58
+    }
59
+
60
+    /**
61
+     * Replace eager code for each foreing key with eager = true 
62
+     *
63
+     * @return $this
64
+     */
65
+    private function replaceEagerCode()
66
+    {
67
+        $storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
68
+        $eagerConditions = $eagerJoins = '';
69
+
70
+        $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
71
+        $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
72
+        $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
73
+        $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
74
+        $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
75
+
76
+        foreach ($this->modelData->fields as $field)
77
+        {
78 78
 			
79
-			// Check foreign key
80
-			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
81
-			{
82
-
83
-				$storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
84
-				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
85
-				$ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
86
-				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
87
-				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
88
-
89
-				// search eager fields
90
-				$foreignModelData = $this->getModelData($field->foreignKey->table);
91
-				$foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
92
-				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
93
-				$eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
94
-				$eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
95
-				$eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
96
-				$eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
97
-				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
98
-			}
99
-
100
-		}
101
-
102
-		$this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
103
-		$this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
104
-		$this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
105
-		$this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
106
-		$this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
107
-		$this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
108
-		$this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
79
+            // Check foreign key
80
+            if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
81
+            {
82
+
83
+                $storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
84
+                $updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
85
+                $ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
86
+                $useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
87
+                $eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
88
+
89
+                // search eager fields
90
+                $foreignModelData = $this->getModelData($field->foreignKey->table);
91
+                $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
92
+                $foreignControllerCompiler->setEagerTable($this->modelData->tableName);
93
+                $eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
94
+                $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
95
+                $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
96
+                $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
97
+                $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
98
+            }
99
+
100
+        }
101
+
102
+        $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
103
+        $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
104
+        $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
105
+        $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
106
+        $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
107
+        $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
108
+        $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
109 109
 		
110 110
 
111 111
 
112
-		return $this;
113
-	}
112
+        return $this;
113
+    }
114 114
 
115 115
 
116
-	public function replaceSortConditions()	{
117
-		$joinSorts = '';
116
+    public function replaceSortConditions()	{
117
+        $joinSorts = '';
118 118
 
119
-		foreach ($this->modelData->fields as $field) {
120
-			if($field->foreignKey){
121
-				$joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
122
-				$joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
123
-				$joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
124
-				$joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
125
-				$joinSorts .= $joinSortStub;
119
+        foreach ($this->modelData->fields as $field) {
120
+            if($field->foreignKey){
121
+                $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
122
+                $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
123
+                $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
124
+                $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
125
+                $joinSorts .= $joinSortStub;
126 126
 
127
-			}
127
+            }
128 128
 			
129 129
 	
130 130
 			
131
-		}
131
+        }
132 132
 		
133 133
 
134
-		$this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
134
+        $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
135 135
 
136
-		return $this;
137
-	}
136
+        return $this;
137
+    }
138 138
 
139
-	public function replaceUniqueRules() {
140
-		$uniqueRules = '';
139
+    public function replaceUniqueRules() {
140
+        $uniqueRules = '';
141 141
 
142
-		foreach ($this->modelData->fields as $field) {
143
-			if (strpos($field->validations, 'unique')) {
144
-				$rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name);
145
-				$uniqueRules .= $rule . "\n";
146
-			}
147
-		}
142
+        foreach ($this->modelData->fields as $field) {
143
+            if (strpos($field->validations, 'unique')) {
144
+                $rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name);
145
+                $uniqueRules .= $rule . "\n";
146
+            }
147
+        }
148 148
 
149
-		$this->stub = str_replace('{{unique_rules}}', $uniqueRules, $this->stub);
149
+        $this->stub = str_replace('{{unique_rules}}', $uniqueRules, $this->stub);
150 150
 
151
-		return $this;
152
-	}
151
+        return $this;
152
+    }
153 153
 
154
-	public function getEagerUniqueRules() {
155
-		$uniqueRules = '';
154
+    public function getEagerUniqueRules() {
155
+        $uniqueRules = '';
156 156
 
157
-		foreach ($this->modelData->fields as $field) {
158
-			if (strpos($field->validations, 'unique')) {
159
-				$rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name);
160
-				$uniqueRules .= $rule . "\n";
161
-			}
162
-		}
157
+        foreach ($this->modelData->fields as $field) {
158
+            if (strpos($field->validations, 'unique')) {
159
+                $rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name);
160
+                $uniqueRules .= $rule . "\n";
161
+            }
162
+        }
163 163
 
164
-		return $uniqueRules;
165
-	}
164
+        return $uniqueRules;
165
+    }
166 166
 
167
-	/**
168
-	 * Replace search conditions
169
-	 *
170
-	 * @return $this
171
-	 */
172
-	private function replaceSearchConditions(){
167
+    /**
168
+     * Replace search conditions
169
+     *
170
+     * @return $this
171
+     */
172
+    private function replaceSearchConditions(){
173 173
 
174
-		$searchConditions = $this->getSearchConditions();
174
+        $searchConditions = $this->getSearchConditions();
175 175
 
176
-		$this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
176
+        $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
177 177
 
178
-		return $this;
179
-	}
178
+        return $this;
179
+    }
180 180
 
181
-	/**
182
-	 * get search conditions
183
-	 *
184
-	 * @return $this
185
-	 */
186
-	public function getSearchConditions(){
181
+    /**
182
+     * get search conditions
183
+     *
184
+     * @return $this
185
+     */
186
+    public function getSearchConditions(){
187 187
 
188
-		$fieldConditions = '';
188
+        $fieldConditions = '';
189 189
 
190
-		$searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
190
+        $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
191 191
 
192
-		foreach ($this->modelData->fields as $field)
193
-		{
192
+        foreach ($this->modelData->fields as $field)
193
+        {
194 194
 
195
-			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
195
+            $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
196 196
 
197
-		}
197
+        }
198 198
 
199
-		// replace all field conditions
200
-		$searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
199
+        // replace all field conditions
200
+        $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
201 201
 
202
-		// replace table name
203
-		$searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
202
+        // replace table name
203
+        $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
204 204
 
205
-		return $searchConditions ;
205
+        return $searchConditions ;
206 206
 
207
-	}
207
+    }
208 208
 
209 209
 
210
-	/**
211
-	 * Replace simple filter
212
-	 *
213
-	 * @return $this
214
-	 */
215
-	private function replaceSimpleFilter(){
216
-		$i = 0;
210
+    /**
211
+     * Replace simple filter
212
+     *
213
+     * @return $this
214
+     */
215
+    private function replaceSimpleFilter(){
216
+        $i = 0;
217 217
 
218
-		$stubSimpleFilter = '';
218
+        $stubSimpleFilter = '';
219 219
 
220
-		foreach ($this->modelData->fields as $field)
221
-		{
222
-			//var_dump($field->name);
220
+        foreach ($this->modelData->fields as $field)
221
+        {
222
+            //var_dump($field->name);
223 223
 			
224
-			if($field->index == 'primary'){
225
-				$dbType = 'primaryKey' ;
226
-			}
227
-			elseif($field->foreignKey){
228
-				$dbType = 'primary' ;
229
-			}
230
-			elseif($field->type->db == 'enum'){
231
-				$dbType = 'primary' ;
232
-			}
233
-			elseif($field->type->db == 'boolean'){
234
-				$dbType = 'primary' ;
235
-			}
236
-			elseif($field->type->db == 'text'){
237
-				$dbType = 'string' ;
238
-			}
239
-			else {
240
-				$dbType = $field->type->db ;
241
-			}
224
+            if($field->index == 'primary'){
225
+                $dbType = 'primaryKey' ;
226
+            }
227
+            elseif($field->foreignKey){
228
+                $dbType = 'primary' ;
229
+            }
230
+            elseif($field->type->db == 'enum'){
231
+                $dbType = 'primary' ;
232
+            }
233
+            elseif($field->type->db == 'boolean'){
234
+                $dbType = 'primary' ;
235
+            }
236
+            elseif($field->type->db == 'text'){
237
+                $dbType = 'string' ;
238
+            }
239
+            else {
240
+                $dbType = $field->type->db ;
241
+            }
242 242
 			
243
-			if($dbType == 'primaryKey')
244
-			{
245
-				$stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
246
-			}
247
-
248
-			if($dbType == 'primary')
249
-			{
250
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
251
-			}
252
-
253
-			if($dbType == 'string')
254
-			{
255
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
256
-			}
257
-
258
-			if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
259
-			{
260
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
261
-			}
262
-
263
-		}
264
-		$stubSimpleFilter .= ';';
265
-		$this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
266
-
267
-		return $this;
268
-	}
269
-
270
-
271
-	/**
272
-	 * replace reverse relationships
273
-	 *
274
-	 * @return $this
275
-	 */
276
-	public function replaceReverseRelationships(){
277
-
278
-		$functions = '';
279
-
280
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php');
281
-
282
-		foreach ($this->modelData->reverseRelationships as $relationship)
283
-		{
284
-			$functionName = '';
285
-			if ($relationship->type == "hasOne")
286
-				$functionName = strtolower($relationship->modelName);
287
-			elseif ($relationship->type == "belongsToMany") 
288
-				$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
289
-			else 
290
-				$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
291
-
292
-			$replacedMethod = '';
293
-			$replacedMethod = str_replace('{{function_name}}', $functionName, $method);
294
-			$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
295
-			$replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
296
-
297
-			$functions .= $replacedMethod;
298
-		}
299
-
300
-		$this->stub = str_replace('{{reverseRelationships}}', $functions, $this->stub);
301
-
302
-		return $this;
303
-
304
-	}
305
-
306
-	/**
307
-	 * replace enum fields
308
-	 *
309
-	 * @return $this
310
-	 */
311
-	public function replaceEnum(){
312
-
313
-		$functions = '';
314
-
315
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php');
316
-
317
-		foreach ($this->modelData->fields as $field)
318
-		{
319
-			if ($field->type->db == "enum") {
320
-				$replacedMethod = '';
321
-				$replacedMethod = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);	
322
-				$replacedMethod = str_replace('{{field_name}}', $field->name, $replacedMethod);
323
-				$replacedMethod = str_replace('{{model_name}}', $this->modelData->modelName, $replacedMethod);
243
+            if($dbType == 'primaryKey')
244
+            {
245
+                $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
246
+            }
247
+
248
+            if($dbType == 'primary')
249
+            {
250
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
251
+            }
252
+
253
+            if($dbType == 'string')
254
+            {
255
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
256
+            }
257
+
258
+            if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
259
+            {
260
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
261
+            }
262
+
263
+        }
264
+        $stubSimpleFilter .= ';';
265
+        $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
266
+
267
+        return $this;
268
+    }
269
+
270
+
271
+    /**
272
+     * replace reverse relationships
273
+     *
274
+     * @return $this
275
+     */
276
+    public function replaceReverseRelationships(){
277
+
278
+        $functions = '';
279
+
280
+        $method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php');
281
+
282
+        foreach ($this->modelData->reverseRelationships as $relationship)
283
+        {
284
+            $functionName = '';
285
+            if ($relationship->type == "hasOne")
286
+                $functionName = strtolower($relationship->modelName);
287
+            elseif ($relationship->type == "belongsToMany") 
288
+                $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
289
+            else 
290
+                $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
291
+
292
+            $replacedMethod = '';
293
+            $replacedMethod = str_replace('{{function_name}}', $functionName, $method);
294
+            $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
295
+            $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
296
+
297
+            $functions .= $replacedMethod;
298
+        }
299
+
300
+        $this->stub = str_replace('{{reverseRelationships}}', $functions, $this->stub);
301
+
302
+        return $this;
303
+
304
+    }
305
+
306
+    /**
307
+     * replace enum fields
308
+     *
309
+     * @return $this
310
+     */
311
+    public function replaceEnum(){
312
+
313
+        $functions = '';
314
+
315
+        $method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php');
316
+
317
+        foreach ($this->modelData->fields as $field)
318
+        {
319
+            if ($field->type->db == "enum") {
320
+                $replacedMethod = '';
321
+                $replacedMethod = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);	
322
+                $replacedMethod = str_replace('{{field_name}}', $field->name, $replacedMethod);
323
+                $replacedMethod = str_replace('{{model_name}}', $this->modelData->modelName, $replacedMethod);
324 324
 				
325
-				$functions .= $replacedMethod;
326
-			}
327
-		}
328
-
329
-		$this->stub = str_replace('{{enum}}', $functions, $this->stub);
330
-
331
-		return $this;
332
-
333
-	}
334
-
335
-	/**
336
-	 * replace relationship tables
337
-	 *
338
-	 * @return $this
339
-	 */
340
-	public function replaceRelationshipTables() {
341
-
342
-		$functions = "";
343
-		$functionsCall = "";
344
-		$removeAll = "";
345
-		$removeAllCall = "";
346
-		$includes = "";
347
-		$joins = "";
348
-		$joinSorts = "";
349
-
350
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php');
351
-
352
-		foreach ($this->modelData->reverseRelationships as $relationship) {
353
-
354
-			if ($relationship->type == "belongsToMany") {
355
-				$relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
356
-				$relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
357
-
358
-				$replacedMethod = '';
359
-				$replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
360
-				$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
361
-				$replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
362
-				$replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
363
-				$replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
364
-				$replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
365
-				$replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
366
-
367
-				$functions .= $replacedMethod;
368
-
369
-				$methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
370
-				$methodCall .= "\n\t\t\t";
371
-				$methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
372
-				$methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
373
-				$methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
374
-				$methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
375
-
376
-				$functionsCall .= $methodCall . "\n\t\t";
325
+                $functions .= $replacedMethod;
326
+            }
327
+        }
328
+
329
+        $this->stub = str_replace('{{enum}}', $functions, $this->stub);
330
+
331
+        return $this;
332
+
333
+    }
334
+
335
+    /**
336
+     * replace relationship tables
337
+     *
338
+     * @return $this
339
+     */
340
+    public function replaceRelationshipTables() {
341
+
342
+        $functions = "";
343
+        $functionsCall = "";
344
+        $removeAll = "";
345
+        $removeAllCall = "";
346
+        $includes = "";
347
+        $joins = "";
348
+        $joinSorts = "";
349
+
350
+        $method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php');
351
+
352
+        foreach ($this->modelData->reverseRelationships as $relationship) {
353
+
354
+            if ($relationship->type == "belongsToMany") {
355
+                $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
356
+                $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
357
+
358
+                $replacedMethod = '';
359
+                $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
360
+                $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
361
+                $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
362
+                $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
363
+                $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
364
+                $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
365
+                $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
366
+
367
+                $functions .= $replacedMethod;
368
+
369
+                $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
370
+                $methodCall .= "\n\t\t\t";
371
+                $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
372
+                $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
373
+                $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
374
+                $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
375
+
376
+                $functionsCall .= $methodCall . "\n\t\t";
377 377
 				
378
-				$removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
379
-				$removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
380
-				$removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
381
-				$removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
382
-				$removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
378
+                $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
379
+                $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
380
+                $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
381
+                $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
382
+                $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
383 383
 				
384
-				$removeAll .= $removeAllMethod;
384
+                $removeAll .= $removeAllMethod;
385 385
 
386
-				$removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
387
-				$removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
388
-				$removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
386
+                $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
387
+                $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
388
+                $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
389 389
 				
390
-				$removeAllCall .= $removeAllCallMethod . "\n\t\t";
390
+                $removeAllCall .= $removeAllCallMethod . "\n\t\t";
391 391
 
392
-				$joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
393
-				$joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
394
-				$joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
395
-				$joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
396
-				$joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
397
-				$joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
398
-				$joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
392
+                $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
393
+                $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
394
+                $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
395
+                $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
396
+                $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
397
+                $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
398
+                $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
399 399
 
400
-				$joins .= $joinRelationshipTableStub . "\n";
400
+                $joins .= $joinRelationshipTableStub . "\n";
401 401
 
402
-				$use = 'use App\Models\{{foreign_table}};';
403
-				$use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
402
+                $use = 'use App\Models\{{foreign_table}};';
403
+                $use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
404 404
 
405
-				$includes .= $use . "\n";
406
-			}
407
-		}
405
+                $includes .= $use . "\n";
406
+            }
407
+        }
408 408
 
409
-		$this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
409
+        $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
410 410
 
411
-		$this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
411
+        $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
412 412
 
413
-		$this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
413
+        $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
414 414
 
415
-		$this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
415
+        $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
416 416
 
417
-		$this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
417
+        $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
418 418
 
419
-		$this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
419
+        $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
420 420
 
421 421
 		
422 422
 		
423
-		return $this;
423
+        return $this;
424 424
 
425
-	}
425
+    }
426 426
 
427 427
 
428
-	/**
429
-	 * replace checkbox fields
430
-	 *
431
-	 * @return $this
432
-	 */
433
-	public function replaceCheckbox(){
428
+    /**
429
+     * replace checkbox fields
430
+     *
431
+     * @return $this
432
+     */
433
+    public function replaceCheckbox(){
434 434
 
435
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php');
436
-		$key = false;
435
+        $method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php');
436
+        $key = false;
437 437
 
438
-		$method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
439
-		$method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
440
-		$method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
441
-		$this->stub = str_replace('{{checkbox}}', $method, $this->stub);
438
+        $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
439
+        $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
440
+        $method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
441
+        $this->stub = str_replace('{{checkbox}}', $method, $this->stub);
442 442
 
443
-		/*foreach ($this->modelData->fields as $field)
443
+        /*foreach ($this->modelData->fields as $field)
444 444
 		{
445 445
 			if ($field->type->ui == "checkbox") {
446 446
 				
@@ -461,49 +461,49 @@  discard block
 block discarded – undo
461 461
 		}*/
462 462
 		
463 463
 
464
-		return $this;
464
+        return $this;
465 465
 
466
-	}
466
+    }
467 467
 
468 468
 
469
-	/**
470
-	 * get search conditions stub by db type
471
-	 *
472
-	 * @param string $field
473
-	 *
474
-	 * @return $this
475
-	 */
476
-	private $conditionsStub = [];
477
-	private function getConditionStubByField($field){
469
+    /**
470
+     * get search conditions stub by db type
471
+     *
472
+     * @param string $field
473
+     *
474
+     * @return $this
475
+     */
476
+    private $conditionsStub = [];
477
+    private function getConditionStubByField($field){
478 478
 		
479
-		if($field->index == 'primary'){
480
-			$dbType = 'primary' ;
481
-		}
482
-		elseif($field->foreignKey){
483
-			$dbType = 'primary' ;
484
-		}
485
-		elseif($field->type->db == 'enum'){
486
-			$dbType = 'primary' ;
487
-		}
488
-		elseif($field->type->db == 'boolean'){
489
-			$dbType = 'primary' ;
490
-		}
491
-		elseif($field->type->db == 'text'){
492
-			$dbType = 'string' ;
493
-		}
494
-		else {
495
-			$dbType = $field->type->db ;
496
-		}
497
-
498
-		if(array_key_exists($dbType, $this->conditionsStub)){
499
-			return $this->conditionsStub[$dbType];
500
-		}
501
-		else {
502
-			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
503
-
504
-			return $this->conditionsStub[$dbType];
505
-		}
506
-	}
479
+        if($field->index == 'primary'){
480
+            $dbType = 'primary' ;
481
+        }
482
+        elseif($field->foreignKey){
483
+            $dbType = 'primary' ;
484
+        }
485
+        elseif($field->type->db == 'enum'){
486
+            $dbType = 'primary' ;
487
+        }
488
+        elseif($field->type->db == 'boolean'){
489
+            $dbType = 'primary' ;
490
+        }
491
+        elseif($field->type->db == 'text'){
492
+            $dbType = 'string' ;
493
+        }
494
+        else {
495
+            $dbType = $field->type->db ;
496
+        }
497
+
498
+        if(array_key_exists($dbType, $this->conditionsStub)){
499
+            return $this->conditionsStub[$dbType];
500
+        }
501
+        else {
502
+            $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
503
+
504
+            return $this->conditionsStub[$dbType];
505
+        }
506
+    }
507 507
 	
508 508
 
509 509
 
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 class ControllerCompiler extends AbstractCompiler
12 12
 {	
13 13
 	protected $cachePrefix 	= 'controller_';
14
-	protected $stubFilename = 'Controller/Controller.php' ;
14
+	protected $stubFilename = 'Controller/Controller.php';
15 15
 	
16 16
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
17 17
 	{
18 18
 		if ($stubName)
19 19
 			$this->stubFilename = $stubName;
20
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
20
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/Api/';
21 21
 		parent::__construct($scaffolderConfig, $modelData);
22 22
 	}
23 23
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	protected function getOutputFilename()
55 55
 	{
56 56
 
57
-		return PathParser::parse($this->scaffolderConfig->generator->paths->controllers) . $this->modelName . 'Controller.php';
57
+		return PathParser::parse($this->scaffolderConfig->generator->paths->controllers).$this->modelName.'Controller.php';
58 58
 	}
59 59
 
60 60
 	/**
@@ -67,11 +67,11 @@  discard block
 block discarded – undo
67 67
 		$storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
68 68
 		$eagerConditions = $eagerJoins = '';
69 69
 
70
-		$storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
71
-		$updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
72
-		$rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
73
-		$useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
74
-		$joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
70
+		$storeEagerStubOriginal = File::get($this->stubsDirectory.'StoreEager.php');
71
+		$updateEagerStubOriginal = File::get($this->stubsDirectory.'UpdateEager.php');
72
+		$rulesEagerStubOriginal = File::get($this->stubsDirectory.'RulesEager.php');
73
+		$useEagerStubOriginal = File::get($this->stubsDirectory.'UseEager.php');
74
+		$joinEagerStubOriginal = File::get($this->stubsDirectory.'SearchConditions/JoinEager.php');
75 75
 
76 76
 		foreach ($this->modelData->fields as $field)
77 77
 		{
@@ -81,20 +81,20 @@  discard block
 block discarded – undo
81 81
 			{
82 82
 
83 83
 				$storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
84
-				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
85
-				$ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
86
-				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
87
-				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
84
+				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal));
85
+				$ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal));
86
+				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal));
87
+				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal);
88 88
 
89 89
 				// search eager fields
90 90
 				$foreignModelData = $this->getModelData($field->foreignKey->table);
91 91
 				$foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
92 92
 				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
93
-				$eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
93
+				$eagerConditions .= $foreignControllerCompiler->getSearchConditions();
94 94
 				$eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
95 95
 				$eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
96 96
 				$eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
97
-				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
97
+				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands);
98 98
 			}
99 99
 
100 100
 		}
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 	}
114 114
 
115 115
 
116
-	public function replaceSortConditions()	{
116
+	public function replaceSortConditions() {
117 117
 		$joinSorts = '';
118 118
 
119 119
 		foreach ($this->modelData->fields as $field) {
120
-			if($field->foreignKey){
121
-				$joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
120
+			if ($field->foreignKey) {
121
+				$joinSortStub = File::get($this->stubsDirectory.'SearchConditions/JoinSort.php');
122 122
 				$joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
123 123
 				$joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
124 124
 				$joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		foreach ($this->modelData->fields as $field) {
143 143
 			if (strpos($field->validations, 'unique')) {
144 144
 				$rule = sprintf('$rules["%s"] = $rules["%s"] . \',%s,\' . $id;', $field->name, $field->name, $field->name);
145
-				$uniqueRules .= $rule . "\n";
145
+				$uniqueRules .= $rule."\n";
146 146
 			}
147 147
 		}
148 148
 
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		foreach ($this->modelData->fields as $field) {
158 158
 			if (strpos($field->validations, 'unique')) {
159 159
 				$rule = sprintf('$rules["%s.%s"] .= \',%s,\' . ${{class_name_lw}}->{{field}};', $this->modelData->tableName, $field->name, $field->name);
160
-				$uniqueRules .= $rule . "\n";
160
+				$uniqueRules .= $rule."\n";
161 161
 			}
162 162
 		}
163 163
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 *
170 170
 	 * @return $this
171 171
 	 */
172
-	private function replaceSearchConditions(){
172
+	private function replaceSearchConditions() {
173 173
 
174 174
 		$searchConditions = $this->getSearchConditions();
175 175
 
@@ -183,16 +183,16 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return $this
185 185
 	 */
186
-	public function getSearchConditions(){
186
+	public function getSearchConditions() {
187 187
 
188 188
 		$fieldConditions = '';
189 189
 
190
-		$searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
190
+		$searchConditions = File::get($this->stubsDirectory.'/SearchConditions/Conditions.php');
191 191
 
192 192
 		foreach ($this->modelData->fields as $field)
193 193
 		{
194 194
 
195
-			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
195
+			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field));
196 196
 
197 197
 		}
198 198
 
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		// replace table name
203 203
 		$searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
204 204
 
205
-		return $searchConditions ;
205
+		return $searchConditions;
206 206
 
207 207
 	}
208 208
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 *
213 213
 	 * @return $this
214 214
 	 */
215
-	private function replaceSimpleFilter(){
215
+	private function replaceSimpleFilter() {
216 216
 		$i = 0;
217 217
 
218 218
 		$stubSimpleFilter = '';
@@ -221,41 +221,41 @@  discard block
 block discarded – undo
221 221
 		{
222 222
 			//var_dump($field->name);
223 223
 			
224
-			if($field->index == 'primary'){
225
-				$dbType = 'primaryKey' ;
224
+			if ($field->index == 'primary') {
225
+				$dbType = 'primaryKey';
226 226
 			}
227
-			elseif($field->foreignKey){
228
-				$dbType = 'primary' ;
227
+			elseif ($field->foreignKey) {
228
+				$dbType = 'primary';
229 229
 			}
230
-			elseif($field->type->db == 'enum'){
231
-				$dbType = 'primary' ;
230
+			elseif ($field->type->db == 'enum') {
231
+				$dbType = 'primary';
232 232
 			}
233
-			elseif($field->type->db == 'boolean'){
234
-				$dbType = 'primary' ;
233
+			elseif ($field->type->db == 'boolean') {
234
+				$dbType = 'primary';
235 235
 			}
236
-			elseif($field->type->db == 'text'){
237
-				$dbType = 'string' ;
236
+			elseif ($field->type->db == 'text') {
237
+				$dbType = 'string';
238 238
 			}
239 239
 			else {
240
-				$dbType = $field->type->db ;
240
+				$dbType = $field->type->db;
241 241
 			}
242 242
 			
243
-			if($dbType == 'primaryKey')
243
+			if ($dbType == 'primaryKey')
244 244
 			{
245 245
 				$stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
246 246
 			}
247 247
 
248
-			if($dbType == 'primary')
248
+			if ($dbType == 'primary')
249 249
 			{
250 250
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
251 251
 			}
252 252
 
253
-			if($dbType == 'string')
253
+			if ($dbType == 'string')
254 254
 			{
255 255
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
256 256
 			}
257 257
 
258
-			if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
258
+			if ($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
259 259
 			{
260 260
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
261 261
 			}
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @return $this
275 275
 	 */
276
-	public function replaceReverseRelationships(){
276
+	public function replaceReverseRelationships() {
277 277
 
278 278
 		$functions = '';
279 279
 
280
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerReverseRelationship.php');
280
+		$method = File::get($this->stubsDirectory.'/Controller/ControllerReverseRelationship.php');
281 281
 
282 282
 		foreach ($this->modelData->reverseRelationships as $relationship)
283 283
 		{
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
 	 *
309 309
 	 * @return $this
310 310
 	 */
311
-	public function replaceEnum(){
311
+	public function replaceEnum() {
312 312
 
313 313
 		$functions = '';
314 314
 
315
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerEnum.php');
315
+		$method = File::get($this->stubsDirectory.'/Controller/ControllerEnum.php');
316 316
 
317 317
 		foreach ($this->modelData->fields as $field)
318 318
 		{
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		$joins = "";
348 348
 		$joinSorts = "";
349 349
 
350
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerRelationshipTable.php');
350
+		$method = File::get($this->stubsDirectory.'/Controller/ControllerRelationshipTable.php');
351 351
 
352 352
 		foreach ($this->modelData->reverseRelationships as $relationship) {
353 353
 
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 				$methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
374 374
 				$methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
375 375
 
376
-				$functionsCall .= $methodCall . "\n\t\t";
376
+				$functionsCall .= $methodCall."\n\t\t";
377 377
 				
378
-				$removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
378
+				$removeAllMethod = File::get($this->stubsDirectory.'/Controller/ControllerRemoveAll.php');
379 379
 				$removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
380 380
 				$removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
381 381
 				$removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
 				$removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
388 388
 				$removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
389 389
 				
390
-				$removeAllCall .= $removeAllCallMethod . "\n\t\t";
390
+				$removeAllCall .= $removeAllCallMethod."\n\t\t";
391 391
 
392
-				$joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
392
+				$joinRelationshipTableStub = File::get($this->stubsDirectory.'SearchConditions/joinRelationshipTable.php');
393 393
 				$joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
394 394
 				$joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
395 395
 				$joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
 				$joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
398 398
 				$joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
399 399
 
400
-				$joins .= $joinRelationshipTableStub . "\n";
400
+				$joins .= $joinRelationshipTableStub."\n";
401 401
 
402 402
 				$use = 'use App\Models\{{foreign_table}};';
403 403
 				$use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
404 404
 
405
-				$includes .= $use . "\n";
405
+				$includes .= $use."\n";
406 406
 			}
407 407
 		}
408 408
 
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
 	 *
431 431
 	 * @return $this
432 432
 	 */
433
-	public function replaceCheckbox(){
433
+	public function replaceCheckbox() {
434 434
 
435
-		$method = File::get($this->stubsDirectory . '/Controller/ControllerCheckbox.php');
435
+		$method = File::get($this->stubsDirectory.'/Controller/ControllerCheckbox.php');
436 436
 		$key = false;
437 437
 
438 438
 		$method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
@@ -474,32 +474,32 @@  discard block
 block discarded – undo
474 474
 	 * @return $this
475 475
 	 */
476 476
 	private $conditionsStub = [];
477
-	private function getConditionStubByField($field){
477
+	private function getConditionStubByField($field) {
478 478
 		
479
-		if($field->index == 'primary'){
480
-			$dbType = 'primary' ;
479
+		if ($field->index == 'primary') {
480
+			$dbType = 'primary';
481 481
 		}
482
-		elseif($field->foreignKey){
483
-			$dbType = 'primary' ;
482
+		elseif ($field->foreignKey) {
483
+			$dbType = 'primary';
484 484
 		}
485
-		elseif($field->type->db == 'enum'){
486
-			$dbType = 'primary' ;
485
+		elseif ($field->type->db == 'enum') {
486
+			$dbType = 'primary';
487 487
 		}
488
-		elseif($field->type->db == 'boolean'){
489
-			$dbType = 'primary' ;
488
+		elseif ($field->type->db == 'boolean') {
489
+			$dbType = 'primary';
490 490
 		}
491
-		elseif($field->type->db == 'text'){
492
-			$dbType = 'string' ;
491
+		elseif ($field->type->db == 'text') {
492
+			$dbType = 'string';
493 493
 		}
494 494
 		else {
495
-			$dbType = $field->type->db ;
495
+			$dbType = $field->type->db;
496 496
 		}
497 497
 
498
-		if(array_key_exists($dbType, $this->conditionsStub)){
498
+		if (array_key_exists($dbType, $this->conditionsStub)) {
499 499
 			return $this->conditionsStub[$dbType];
500 500
 		}
501 501
 		else {
502
-			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
502
+			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory.'SearchConditions/'.ucwords($dbType).'.php'); ;
503 503
 
504 504
 			return $this->conditionsStub[$dbType];
505 505
 		}
Please login to merge, or discard this patch.
Braces   +21 added lines, -30 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
 	
16 16
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
17 17
 	{
18
-		if ($stubName)
19
-			$this->stubFilename = $stubName;
18
+		if ($stubName) {
19
+					$this->stubFilename = $stubName;
20
+		}
20 21
 		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21 22
 		parent::__construct($scaffolderConfig, $modelData);
22 23
 	}
@@ -223,20 +224,15 @@  discard block
 block discarded – undo
223 224
 			
224 225
 			if($field->index == 'primary'){
225 226
 				$dbType = 'primaryKey' ;
226
-			}
227
-			elseif($field->foreignKey){
227
+			} elseif($field->foreignKey){
228 228
 				$dbType = 'primary' ;
229
-			}
230
-			elseif($field->type->db == 'enum'){
229
+			} elseif($field->type->db == 'enum'){
231 230
 				$dbType = 'primary' ;
232
-			}
233
-			elseif($field->type->db == 'boolean'){
231
+			} elseif($field->type->db == 'boolean'){
234 232
 				$dbType = 'primary' ;
235
-			}
236
-			elseif($field->type->db == 'text'){
233
+			} elseif($field->type->db == 'text'){
237 234
 				$dbType = 'string' ;
238
-			}
239
-			else {
235
+			} else {
240 236
 				$dbType = $field->type->db ;
241 237
 			}
242 238
 			
@@ -282,12 +278,13 @@  discard block
 block discarded – undo
282 278
 		foreach ($this->modelData->reverseRelationships as $relationship)
283 279
 		{
284 280
 			$functionName = '';
285
-			if ($relationship->type == "hasOne")
286
-				$functionName = strtolower($relationship->modelName);
287
-			elseif ($relationship->type == "belongsToMany") 
288
-				$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
289
-			else 
290
-				$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
281
+			if ($relationship->type == "hasOne") {
282
+							$functionName = strtolower($relationship->modelName);
283
+			} elseif ($relationship->type == "belongsToMany") {
284
+							$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
285
+			} else {
286
+							$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
287
+			}
291 288
 
292 289
 			$replacedMethod = '';
293 290
 			$replacedMethod = str_replace('{{function_name}}', $functionName, $method);
@@ -478,27 +475,21 @@  discard block
 block discarded – undo
478 475
 		
479 476
 		if($field->index == 'primary'){
480 477
 			$dbType = 'primary' ;
481
-		}
482
-		elseif($field->foreignKey){
478
+		} elseif($field->foreignKey){
483 479
 			$dbType = 'primary' ;
484
-		}
485
-		elseif($field->type->db == 'enum'){
480
+		} elseif($field->type->db == 'enum'){
486 481
 			$dbType = 'primary' ;
487
-		}
488
-		elseif($field->type->db == 'boolean'){
482
+		} elseif($field->type->db == 'boolean'){
489 483
 			$dbType = 'primary' ;
490
-		}
491
-		elseif($field->type->db == 'text'){
484
+		} elseif($field->type->db == 'text'){
492 485
 			$dbType = 'string' ;
493
-		}
494
-		else {
486
+		} else {
495 487
 			$dbType = $field->type->db ;
496 488
 		}
497 489
 
498 490
 		if(array_key_exists($dbType, $this->conditionsStub)){
499 491
 			return $this->conditionsStub[$dbType];
500
-		}
501
-		else {
492
+		} else {
502 493
 			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
503 494
 
504 495
 			return $this->conditionsStub[$dbType];
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/MigrationCompiler.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	/**
28 28
 	 * Replace and store the Stub.
29 29
 	 *
30
-	 * @return string
30
+	 * @return MigrationCompiler
31 31
 	 */
32 32
 	public function replaceAndStore()
33 33
 	{
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * Get output filename
42 42
 	 *
43 43
 	 *
44
-	 * @return $this
44
+	 * @return string
45 45
 	 */
46 46
 	protected function getOutputFilename()
47 47
 	{
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace Scaffolder\Compilers\Core;
4 4
 
5 5
 use Carbon\Carbon;
6
-use Illuminate\Support\Facades\File;
7 6
 use Scaffolder\Compilers\AbstractCompiler;
8 7
 use Scaffolder\Compilers\Support\FileToCompile;
9 8
 use Scaffolder\Compilers\Support\PathParser;
Please login to merge, or discard this patch.
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -10,130 +10,130 @@
 block discarded – undo
10 10
 
11 11
 class MigrationCompiler extends AbstractCompiler
12 12
 {
13
-	private $date;
13
+    private $date;
14 14
 
15
-	protected $cachePrefix 	= 'migration_';
16
-	protected $stubFilename = 'Migration.php' ;
15
+    protected $cachePrefix 	= 'migration_';
16
+    protected $stubFilename = 'Migration.php' ;
17 17
 
18
-	public function __construct($scaffolderConfig, $modelData = null)
19
-	{
20
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
18
+    public function __construct($scaffolderConfig, $modelData = null)
19
+    {
20
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21 21
 
22
-		parent::__construct($scaffolderConfig, $modelData);
22
+        parent::__construct($scaffolderConfig, $modelData);
23 23
 
24
-		$this->date = Carbon::now();
25
-	}
24
+        $this->date = Carbon::now();
25
+    }
26 26
 
27
-	/**
28
-	 * Replace and store the Stub.
29
-	 *
30
-	 * @return string
31
-	 */
32
-	public function replaceAndStore()
33
-	{
27
+    /**
28
+     * Replace and store the Stub.
29
+     *
30
+     * @return string
31
+     */
32
+    public function replaceAndStore()
33
+    {
34 34
 		
35
-		return $this->addFields()
36
-					->store(new FileToCompile(false, $this->modelData->modelHash));
35
+        return $this->addFields()
36
+                    ->store(new FileToCompile(false, $this->modelData->modelHash));
37 37
 		
38
-	}
39
-
40
-	/**
41
-	 * Get output filename
42
-	 *
43
-	 *
44
-	 * @return $this
45
-	 */
46
-	protected function getOutputFilename()
47
-	{
48
-
49
-		return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php';
50
-	}
51
-
52
-	/**
53
-	 * Add fields.
54
-	 *
55
-	 * @param $modelData
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	private function addFields()
60
-	{
61
-		// Default primary key
62
-		$fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL;
63
-
64
-		// Check primary key
65
-		# TODO FIX, primary
38
+    }
39
+
40
+    /**
41
+     * Get output filename
42
+     *
43
+     *
44
+     * @return $this
45
+     */
46
+    protected function getOutputFilename()
47
+    {
48
+
49
+        return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php';
50
+    }
51
+
52
+    /**
53
+     * Add fields.
54
+     *
55
+     * @param $modelData
56
+     *
57
+     * @return $this
58
+     */
59
+    private function addFields()
60
+    {
61
+        // Default primary key
62
+        $fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL;
63
+
64
+        // Check primary key
65
+        # TODO FIX, primary
66 66
 		
67
-		foreach ($this->modelData->fields as $field)
68
-		{
69
-			$parsedModifiers = '';
70
-
71
-			if($field->index == "primary")
72
-				continue ;
73
-			if($this->modelData->timeStamps && $field->name == "created_at")
74
-				continue ;
75
-			if($this->modelData->timeStamps && $field->name == "updated_at")
76
-				continue ;
77
-
78
-			// Check modifiers
79
-			if (!empty($field->modifiers))
80
-			{
81
-				$modifiersArray = explode(':', $field->modifiers);
82
-
83
-				foreach ($modifiersArray as $modifier)
84
-				{
85
-					$modifierAndValue = explode(',', $modifier);
86
-
87
-					if (count($modifierAndValue) == 2)
88
-					{
89
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
90
-					}
91
-					else
92
-					{
93
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '()';
94
-					}
95
-				}
96
-			}
97
-
98
-			// Check foreign key for unsigned modifier
99
-			if ($field->foreignKey)
100
-			{
101
-				$parsedModifiers .= '->unsigned()';
102
-			}
103
-
104
-			// Check indexes
105
-			if ($field->index != 'none')
106
-			{
107
-				$fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108
-			}
109
-			else
110
-			{
111
-				if ($field->type->db == "enum") {
112
-					$items = '';
113
-					foreach ($field->options as $key => $option) {
114
-						$items .= "'" . $option . "'";
115
-						if ($key < (count($field->options) - 1))
116
-							$items .= ", ";
117
-					}
118
-
119
-					$fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
120
-				}
121
-				else
122
-					$fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123
-			}
124
-
125
-			// Check foreign key
126
-			if ($field->foreignKey)
127
-			{
128
-				$fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
129
-			}
130
-		}
131
-
132
-		if($this->modelData->timeStamps)
133
-			$fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
134
-
135
-		$this->stub = str_replace('{{fields}}', $fields, $this->stub);
136
-
137
-		return $this;
138
-	}
67
+        foreach ($this->modelData->fields as $field)
68
+        {
69
+            $parsedModifiers = '';
70
+
71
+            if($field->index == "primary")
72
+                continue ;
73
+            if($this->modelData->timeStamps && $field->name == "created_at")
74
+                continue ;
75
+            if($this->modelData->timeStamps && $field->name == "updated_at")
76
+                continue ;
77
+
78
+            // Check modifiers
79
+            if (!empty($field->modifiers))
80
+            {
81
+                $modifiersArray = explode(':', $field->modifiers);
82
+
83
+                foreach ($modifiersArray as $modifier)
84
+                {
85
+                    $modifierAndValue = explode(',', $modifier);
86
+
87
+                    if (count($modifierAndValue) == 2)
88
+                    {
89
+                        $parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
90
+                    }
91
+                    else
92
+                    {
93
+                        $parsedModifiers .= '->' . $modifierAndValue[0] . '()';
94
+                    }
95
+                }
96
+            }
97
+
98
+            // Check foreign key for unsigned modifier
99
+            if ($field->foreignKey)
100
+            {
101
+                $parsedModifiers .= '->unsigned()';
102
+            }
103
+
104
+            // Check indexes
105
+            if ($field->index != 'none')
106
+            {
107
+                $fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108
+            }
109
+            else
110
+            {
111
+                if ($field->type->db == "enum") {
112
+                    $items = '';
113
+                    foreach ($field->options as $key => $option) {
114
+                        $items .= "'" . $option . "'";
115
+                        if ($key < (count($field->options) - 1))
116
+                            $items .= ", ";
117
+                    }
118
+
119
+                    $fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
120
+                }
121
+                else
122
+                    $fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123
+            }
124
+
125
+            // Check foreign key
126
+            if ($field->foreignKey)
127
+            {
128
+                $fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
129
+            }
130
+        }
131
+
132
+        if($this->modelData->timeStamps)
133
+            $fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
134
+
135
+        $this->stub = str_replace('{{fields}}', $fields, $this->stub);
136
+
137
+        return $this;
138
+    }
139 139
 }
140 140
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 	private $date;
14 14
 
15 15
 	protected $cachePrefix 	= 'migration_';
16
-	protected $stubFilename = 'Migration.php' ;
16
+	protected $stubFilename = 'Migration.php';
17 17
 
18 18
 	public function __construct($scaffolderConfig, $modelData = null)
19 19
 	{
20
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
20
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/Api/';
21 21
 
22 22
 		parent::__construct($scaffolderConfig, $modelData);
23 23
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	protected function getOutputFilename()
47 47
 	{
48 48
 
49
-		return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations) . $this->date->format('Y_m_d_') . str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT) . '_create_' . strtolower($this->modelName) . '_table.php';
49
+		return  PathParser::parse($this->scaffolderConfig->generator->paths->migrations).$this->date->format('Y_m_d_').str_pad($this->modelData->migrationOrder, 2, 0, STR_PAD_LEFT).'_create_'.strtolower($this->modelName).'_table.php';
50 50
 	}
51 51
 
52 52
 	/**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	private function addFields()
60 60
 	{
61 61
 		// Default primary key
62
-		$fields = "\t\t\t\$table->increments('id');" . PHP_EOL . PHP_EOL;
62
+		$fields = "\t\t\t\$table->increments('id');".PHP_EOL.PHP_EOL;
63 63
 
64 64
 		// Check primary key
65 65
 		# TODO FIX, primary
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 		{
69 69
 			$parsedModifiers = '';
70 70
 
71
-			if($field->index == "primary")
72
-				continue ;
73
-			if($this->modelData->timeStamps && $field->name == "created_at")
74
-				continue ;
75
-			if($this->modelData->timeStamps && $field->name == "updated_at")
76
-				continue ;
71
+			if ($field->index == "primary")
72
+				continue;
73
+			if ($this->modelData->timeStamps && $field->name == "created_at")
74
+				continue;
75
+			if ($this->modelData->timeStamps && $field->name == "updated_at")
76
+				continue;
77 77
 
78 78
 			// Check modifiers
79 79
 			if (!empty($field->modifiers))
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 
87 87
 					if (count($modifierAndValue) == 2)
88 88
 					{
89
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
89
+						$parsedModifiers .= '->'.$modifierAndValue[0].'('.$modifierAndValue[1].')';
90 90
 					}
91 91
 					else
92 92
 					{
93
-						$parsedModifiers .= '->' . $modifierAndValue[0] . '()';
93
+						$parsedModifiers .= '->'.$modifierAndValue[0].'()';
94 94
 					}
95 95
 				}
96 96
 			}
@@ -104,33 +104,33 @@  discard block
 block discarded – undo
104 104
 			// Check indexes
105 105
 			if ($field->index != 'none')
106 106
 			{
107
-				$fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
107
+				$fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();".PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108 108
 			}
109 109
 			else
110 110
 			{
111 111
 				if ($field->type->db == "enum") {
112 112
 					$items = '';
113 113
 					foreach ($field->options as $key => $option) {
114
-						$items .= "'" . $option . "'";
114
+						$items .= "'".$option."'";
115 115
 						if ($key < (count($field->options) - 1))
116 116
 							$items .= ", ";
117 117
 					}
118 118
 
119
-					$fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
119
+					$fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));".PHP_EOL, $field->type->db, $field->name, $items);
120 120
 				}
121 121
 				else
122
-					$fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
122
+					$fields .= sprintf("\t\t\t\$table->%s('%s')%s;".PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123 123
 			}
124 124
 
125 125
 			// Check foreign key
126 126
 			if ($field->foreignKey)
127 127
 			{
128
-				$fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');" . PHP_EOL . PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
128
+				$fields .= sprintf("\t\t\t\$table->foreign('%s')->references('%s')->on('%s');".PHP_EOL.PHP_EOL, $field->name, $field->foreignKey->field, $field->foreignKey->table);
129 129
 			}
130 130
 		}
131 131
 
132
-		if($this->modelData->timeStamps)
133
-			$fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
132
+		if ($this->modelData->timeStamps)
133
+			$fields .= PHP_EOL."\t\t\t\$table->timestamps();".PHP_EOL;
134 134
 
135 135
 		$this->stub = str_replace('{{fields}}', $fields, $this->stub);
136 136
 
Please login to merge, or discard this patch.
Braces   +19 added lines, -16 removed lines patch added patch discarded remove patch
@@ -68,12 +68,15 @@  discard block
 block discarded – undo
68 68
 		{
69 69
 			$parsedModifiers = '';
70 70
 
71
-			if($field->index == "primary")
72
-				continue ;
73
-			if($this->modelData->timeStamps && $field->name == "created_at")
74
-				continue ;
75
-			if($this->modelData->timeStamps && $field->name == "updated_at")
76
-				continue ;
71
+			if($field->index == "primary") {
72
+							continue ;
73
+			}
74
+			if($this->modelData->timeStamps && $field->name == "created_at") {
75
+							continue ;
76
+			}
77
+			if($this->modelData->timeStamps && $field->name == "updated_at") {
78
+							continue ;
79
+			}
77 80
 
78 81
 			// Check modifiers
79 82
 			if (!empty($field->modifiers))
@@ -87,8 +90,7 @@  discard block
 block discarded – undo
87 90
 					if (count($modifierAndValue) == 2)
88 91
 					{
89 92
 						$parsedModifiers .= '->' . $modifierAndValue[0] . '(' . $modifierAndValue[1] . ')';
90
-					}
91
-					else
93
+					} else
92 94
 					{
93 95
 						$parsedModifiers .= '->' . $modifierAndValue[0] . '()';
94 96
 					}
@@ -105,21 +107,21 @@  discard block
 block discarded – undo
105 107
 			if ($field->index != 'none')
106 108
 			{
107 109
 				$fields .= sprintf("\t\t\t\$table->%s('%s')%s->%s();" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers, $field->index);
108
-			}
109
-			else
110
+			} else
110 111
 			{
111 112
 				if ($field->type->db == "enum") {
112 113
 					$items = '';
113 114
 					foreach ($field->options as $key => $option) {
114 115
 						$items .= "'" . $option . "'";
115
-						if ($key < (count($field->options) - 1))
116
-							$items .= ", ";
116
+						if ($key < (count($field->options) - 1)) {
117
+													$items .= ", ";
118
+						}
117 119
 					}
118 120
 
119 121
 					$fields .= sprintf("\t\t\t\$table->%s('%s', array(%s));" . PHP_EOL, $field->type->db, $field->name, $items);
122
+				} else {
123
+									$fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
120 124
 				}
121
-				else
122
-					$fields .= sprintf("\t\t\t\$table->%s('%s')%s;" . PHP_EOL, $field->type->db, $field->name, $parsedModifiers);
123 125
 			}
124 126
 
125 127
 			// Check foreign key
@@ -129,8 +131,9 @@  discard block
 block discarded – undo
129 131
 			}
130 132
 		}
131 133
 
132
-		if($this->modelData->timeStamps)
133
-			$fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
134
+		if($this->modelData->timeStamps) {
135
+					$fields .= PHP_EOL . "\t\t\t\$table->timestamps();" . PHP_EOL;
136
+		}
134 137
 
135 138
 		$this->stub = str_replace('{{fields}}', $fields, $this->stub);
136 139
 
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/ModelCompiler.php 5 patches
Doc Comments   +9 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,6 +14,9 @@  discard block
 block discarded – undo
14 14
 	protected $cachePrefix 	= 'model_';
15 15
 	protected $stubFilename = 'Model/Model.php' ;
16 16
 
17
+	/**
18
+	 * @param string $stubName
19
+	 */
17 20
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18 21
 	{
19 22
 		if ($stubName)
@@ -25,7 +28,7 @@  discard block
 block discarded – undo
25 28
 	/**
26 29
 	 * Replace and store the Stub.
27 30
 	 *
28
-	 * @return string
31
+	 * @return ModelCompiler
29 32
 	 */
30 33
 	public function replaceAndStore()
31 34
 	{
@@ -54,7 +57,7 @@  discard block
 block discarded – undo
54 57
 	 * Get output filename
55 58
 	 *
56 59
 	 *
57
-	 * @return $this
60
+	 * @return string
58 61
 	 */
59 62
 	protected function getOutputFilename()
60 63
 	{
@@ -528,6 +531,10 @@  discard block
 block discarded – undo
528 531
 	 * @return $this
529 532
 	 */
530 533
 	private $conditionsStub = [];
534
+
535
+	/**
536
+	 * @return string
537
+	 */
531 538
 	private function getConditionStubByField($field){
532 539
 		
533 540
 		if($field->index == 'primary'){
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 use Scaffolder\Compilers\AbstractCompiler;
7 7
 use Scaffolder\Compilers\Support\FileToCompile;
8 8
 use Scaffolder\Compilers\Support\PathParser;
9
-use Scaffolder\Support\Directory;
10 9
 use Scaffolder\Support\CamelCase;
11 10
 
12 11
 class ModelCompiler extends AbstractCompiler
Please login to merge, or discard this patch.
Indentation   +569 added lines, -569 removed lines patch added patch discarded remove patch
@@ -11,692 +11,692 @@
 block discarded – undo
11 11
 
12 12
 class ModelCompiler extends AbstractCompiler
13 13
 {
14
-	protected $cachePrefix 	= 'model_';
15
-	protected $stubFilename = 'Model/Model.php' ;
16
-
17
-	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18
-	{
19
-		if ($stubName)
20
-			$this->stubFilename = $stubName;
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
-		parent::__construct($scaffolderConfig, $modelData);
23
-	}
24
-
25
-	/**
26
-	 * Replace and store the Stub.
27
-	 *
28
-	 * @return string
29
-	 */
30
-	public function replaceAndStore()
31
-	{
14
+    protected $cachePrefix 	= 'model_';
15
+    protected $stubFilename = 'Model/Model.php' ;
16
+
17
+    public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18
+    {
19
+        if ($stubName)
20
+            $this->stubFilename = $stubName;
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
+        parent::__construct($scaffolderConfig, $modelData);
23
+    }
24
+
25
+    /**
26
+     * Replace and store the Stub.
27
+     *
28
+     * @return string
29
+     */
30
+    public function replaceAndStore()
31
+    {
32 32
 		
33
-		return $this->replaceNamespace()
34
-				->replaceNamespaceModelExtend()
35
-				->setPrimaryKey()
36
-				->setTimeStamps()
37
-				->addFillable()
38
-				->addEnumFields()
39
-				->addRules()
40
-				->addBelongsTo()
41
-				->addReverseRelationship()
42
-				->replaceEagerCode()
43
-				->replaceRelationshipTables()
44
-				->replaceSearchConditions()
45
-				->replaceSimpleFilter()
46
-				->replaceSortConditions()
47
-				->replaceReverseRelationshipsFunctions()
48
-				->replaceCheckbox()
49
-				->store(new FileToCompile(false, $this->modelData->modelHash));
33
+        return $this->replaceNamespace()
34
+                ->replaceNamespaceModelExtend()
35
+                ->setPrimaryKey()
36
+                ->setTimeStamps()
37
+                ->addFillable()
38
+                ->addEnumFields()
39
+                ->addRules()
40
+                ->addBelongsTo()
41
+                ->addReverseRelationship()
42
+                ->replaceEagerCode()
43
+                ->replaceRelationshipTables()
44
+                ->replaceSearchConditions()
45
+                ->replaceSimpleFilter()
46
+                ->replaceSortConditions()
47
+                ->replaceReverseRelationshipsFunctions()
48
+                ->replaceCheckbox()
49
+                ->store(new FileToCompile(false, $this->modelData->modelHash));
50 50
 		
51
-	}
51
+    }
52 52
 	
53
-	/**
54
-	 * Get output filename
55
-	 *
56
-	 *
57
-	 * @return $this
58
-	 */
59
-	protected function getOutputFilename()
60
-	{
61
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ;
62
-
63
-		return $folder .  $this->modelName . '.php';
64
-	}
53
+    /**
54
+     * Get output filename
55
+     *
56
+     *
57
+     * @return $this
58
+     */
59
+    protected function getOutputFilename()
60
+    {
61
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ;
62
+
63
+        return $folder .  $this->modelName . '.php';
64
+    }
65 65
 
66 66
 	
67 67
 
68
-	/**
69
-	 * Replace the namespace which the model extends
70
-	 *
71
-	 * @param $this->scaffolderConfig
72
-	 *
73
-	 * @return $this
74
-	 */
75
-	private function replaceNamespaceModelExtend()
76
-	{
77
-		$this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub);
78
-
79
-		return $this;
80
-	}
81
-
82
-	/**
83
-	 * Add fillable.
84
-	 *
85
-	 * @return $this
86
-	 */
87
-	private function addFillable()
88
-	{
89
-		$fields = '';
90
-		$firstIteration = true;
91
-
92
-		foreach ($this->modelData->fields as $field)
93
-		{
94
-			if($field->index == "primary")
95
-				continue ;
96
-			if($this->modelData->timeStamps && $field->name == "created_at")
97
-				continue ;
98
-			if($this->modelData->timeStamps && $field->name == "updated_at")
99
-				continue ;
100
-
101
-			if ($firstIteration)
102
-			{
103
-				$fields .= sprintf("'%s'," . PHP_EOL, $field->name);
104
-				$firstIteration = false;
105
-			}
106
-			else
107
-			{
108
-				$fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
109
-			}
110
-		}
111
-
112
-		$this->stub = str_replace('{{fillable}}', $fields, $this->stub);
113
-
114
-		return $this;
115
-	}
116
-
117
-	private function addEnumFields() {
118
-
119
-		$items = '';
120
-		$arrays = '';
68
+    /**
69
+     * Replace the namespace which the model extends
70
+     *
71
+     * @param $this->scaffolderConfig
72
+     *
73
+     * @return $this
74
+     */
75
+    private function replaceNamespaceModelExtend()
76
+    {
77
+        $this->stub = str_replace('{{namespace_model_extend}}', $this->scaffolderConfig->generator->inheritance->model, $this->stub);
78
+
79
+        return $this;
80
+    }
81
+
82
+    /**
83
+     * Add fillable.
84
+     *
85
+     * @return $this
86
+     */
87
+    private function addFillable()
88
+    {
89
+        $fields = '';
90
+        $firstIteration = true;
91
+
92
+        foreach ($this->modelData->fields as $field)
93
+        {
94
+            if($field->index == "primary")
95
+                continue ;
96
+            if($this->modelData->timeStamps && $field->name == "created_at")
97
+                continue ;
98
+            if($this->modelData->timeStamps && $field->name == "updated_at")
99
+                continue ;
100
+
101
+            if ($firstIteration)
102
+            {
103
+                $fields .= sprintf("'%s'," . PHP_EOL, $field->name);
104
+                $firstIteration = false;
105
+            }
106
+            else
107
+            {
108
+                $fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
109
+            }
110
+        }
111
+
112
+        $this->stub = str_replace('{{fillable}}', $fields, $this->stub);
113
+
114
+        return $this;
115
+    }
116
+
117
+    private function addEnumFields() {
118
+
119
+        $items = '';
120
+        $arrays = '';
121 121
 		
122
-		foreach ($this->modelData->fields as $field) {
123
-			$enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php');
122
+        foreach ($this->modelData->fields as $field) {
123
+            $enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php');
124 124
 
125
-			if ($field->type->db == "enum") {
126
-				$items = '';
125
+            if ($field->type->db == "enum") {
126
+                $items = '';
127 127
 				
128
-				foreach ($field->options as $key => $option) {
129
-					$items .= "'" . $option . "'";
130
-					if ($key < (count($field->options) - 1))
131
-						$items .= ", ";
128
+                foreach ($field->options as $key => $option) {
129
+                    $items .= "'" . $option . "'";
130
+                    if ($key < (count($field->options) - 1))
131
+                        $items .= ", ";
132 132
 
133
-				}
133
+                }
134 134
 
135 135
 
136
-				$enumStub = str_replace('{{field_options}}', $items, $enumStub);
137
-				$enumStub = str_replace('{{field_name}}', $field->name, $enumStub);	
136
+                $enumStub = str_replace('{{field_options}}', $items, $enumStub);
137
+                $enumStub = str_replace('{{field_name}}', $field->name, $enumStub);	
138 138
 					
139
-				$arrays .= $enumStub;
139
+                $arrays .= $enumStub;
140 140
 
141 141
 				
142
-			}
143
-		}
144
-
145
-		$this->stub = str_replace('{{enum}}', $arrays, $this->stub);
146
-
147
-		return $this;
148
-	}
149
-
150
-	/**
151
-	 * Set validations.
152
-	 *
153
-	 *
154
-	 * @return $this
155
-	 */
156
-	private function addRules()
157
-	{
158
-		$fields = '';
159
-		$firstIteration = true;
160
-
161
-		foreach ($this->modelData->fields as $field)
162
-		{
163
-			if($field->index == "primary")
164
-				continue ;
165
-			if($this->modelData->timeStamps && $field->name == "created_at")
166
-				continue ;
167
-			if($this->modelData->timeStamps && $field->name == "updated_at")
168
-				continue ;
169
-
170
-			if ($firstIteration)
171
-			{
172
-				$fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
173
-				$firstIteration = false;
174
-			}
175
-			else
176
-			{
177
-				$fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
178
-			}
179
-		}
180
-
181
-		$fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields);
182
-		//var_dump($fields);
183
-
184
-		$this->stub = str_replace('{{validations}}', $fields, $this->stub);
185
-
186
-		return $this;
187
-	}
188
-
189
-	/**
190
-	 * Set the timestamps value.
191
-	 *
192
-	 */
193
-	private function setTimeStamps()
194
-	{
195
-		if($this->modelData->timeStamps)
196
-		{
197
-			$this->stub = str_replace('{{timestamps}}', ' ', $this->stub);
198
-		} else {
199
-			$this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub);
200
-		}
201
-
202
-		return $this;
203
-	}
204
-
205
-	/**
206
-	 *  Set the primary key.
207
-	 *
208
-	 */
209
-	private function setPrimaryKey()
210
-	{
211
-		$primaryKey = '// Using default primary key' . PHP_EOL;
212
-
213
-		$field = $this->getPrimaryKeyField() ;
214
-
215
-		$primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL;
216
-
217
-		$this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub);
218
-
219
-		return $this;
220
-	}
221
-
222
-	/**
223
-	 * Add belongsTo Relationships.
224
-	 *
225
-	 *
226
-	 * @return $this
227
-	 */
228
-	private function addBelongsTo()
229
-	{
230
-		$functions = '';
231
-
232
-		$eagerArray = [];
142
+            }
143
+        }
144
+
145
+        $this->stub = str_replace('{{enum}}', $arrays, $this->stub);
146
+
147
+        return $this;
148
+    }
149
+
150
+    /**
151
+     * Set validations.
152
+     *
153
+     *
154
+     * @return $this
155
+     */
156
+    private function addRules()
157
+    {
158
+        $fields = '';
159
+        $firstIteration = true;
160
+
161
+        foreach ($this->modelData->fields as $field)
162
+        {
163
+            if($field->index == "primary")
164
+                continue ;
165
+            if($this->modelData->timeStamps && $field->name == "created_at")
166
+                continue ;
167
+            if($this->modelData->timeStamps && $field->name == "updated_at")
168
+                continue ;
169
+
170
+            if ($firstIteration)
171
+            {
172
+                $fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
173
+                $firstIteration = false;
174
+            }
175
+            else
176
+            {
177
+                $fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
178
+            }
179
+        }
180
+
181
+        $fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields);
182
+        //var_dump($fields);
183
+
184
+        $this->stub = str_replace('{{validations}}', $fields, $this->stub);
185
+
186
+        return $this;
187
+    }
188
+
189
+    /**
190
+     * Set the timestamps value.
191
+     *
192
+     */
193
+    private function setTimeStamps()
194
+    {
195
+        if($this->modelData->timeStamps)
196
+        {
197
+            $this->stub = str_replace('{{timestamps}}', ' ', $this->stub);
198
+        } else {
199
+            $this->stub = str_replace('{{timestamps}}', 'public $timestamps = false;', $this->stub);
200
+        }
201
+
202
+        return $this;
203
+    }
204
+
205
+    /**
206
+     *  Set the primary key.
207
+     *
208
+     */
209
+    private function setPrimaryKey()
210
+    {
211
+        $primaryKey = '// Using default primary key' . PHP_EOL;
212
+
213
+        $field = $this->getPrimaryKeyField() ;
214
+
215
+        $primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL;
216
+
217
+        $this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub);
218
+
219
+        return $this;
220
+    }
221
+
222
+    /**
223
+     * Add belongsTo Relationships.
224
+     *
225
+     *
226
+     * @return $this
227
+     */
228
+    private function addBelongsTo()
229
+    {
230
+        $functions = '';
231
+
232
+        $eagerArray = [];
233 233
 		
234
-		foreach ($this->modelData->fields as $field)
235
-		{
234
+        foreach ($this->modelData->fields as $field)
235
+        {
236 236
 			
237
-			// Check foreign key
238
-			if (isset($field->foreignKey->relationship))
239
-			{
240
-				$belongsToStub = "";
241
-				$functionName = $field->foreignKey->table;
242
-
243
-				if ($field->foreignKey->relationship == "belongsTo") {
244
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php');
245
-					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246
-					$belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247
-					$belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248
-				}
249
-				elseif ($field->foreignKey->relationship == "belongsToMany") {
250
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
251
-					$functionName = CamelCase::pluralize($field->foreignKey->table);
252
-					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
253
-					$belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub);
254
-					$belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub);
255
-					$belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub);
256
-				}
237
+            // Check foreign key
238
+            if (isset($field->foreignKey->relationship))
239
+            {
240
+                $belongsToStub = "";
241
+                $functionName = $field->foreignKey->table;
242
+
243
+                if ($field->foreignKey->relationship == "belongsTo") {
244
+                    $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php');
245
+                    $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246
+                    $belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247
+                    $belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248
+                }
249
+                elseif ($field->foreignKey->relationship == "belongsToMany") {
250
+                    $belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
251
+                    $functionName = CamelCase::pluralize($field->foreignKey->table);
252
+                    $belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
253
+                    $belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub);
254
+                    $belongsToStub = str_replace('{{related_field}}', $field->foreignKey->field, $belongsToStub);
255
+                    $belongsToStub = str_replace('{{table_name}}', $field->foreignKey->table, $belongsToStub);
256
+                }
257 257
 				
258
-				$belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub);
259
-				$belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub);
258
+                $belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub);
259
+                $belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub);
260 260
 				
261
-				$functions .= $belongsToStub ;
261
+                $functions .= $belongsToStub ;
262 262
 
263
-				if(isset($field->foreignKey->eager) && $field->foreignKey->eager){
264
-					array_push($eagerArray, "'".$field->foreignKey->table."'");
265
-				}
266
-			}
263
+                if(isset($field->foreignKey->eager) && $field->foreignKey->eager){
264
+                    array_push($eagerArray, "'".$field->foreignKey->table."'");
265
+                }
266
+            }
267 267
 
268 268
 			
269
-		}
269
+        }
270 270
 
271
-		$this->stub = str_replace('{{belongsTo}}', $functions, $this->stub);
271
+        $this->stub = str_replace('{{belongsTo}}', $functions, $this->stub);
272 272
 
273
-		$this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub);
273
+        $this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub);
274 274
 
275
-		return $this;
276
-	}
275
+        return $this;
276
+    }
277 277
 
278
-	private function addReverseRelationship()
279
-	{
280
-		$functions = '';
278
+    private function addReverseRelationship()
279
+    {
280
+        $functions = '';
281 281
 
282
-		$eagerArray = [];
282
+        $eagerArray = [];
283 283
 
284
-		foreach ($this->modelData->reverseRelationships as $relationship)
285
-		{
284
+        foreach ($this->modelData->reverseRelationships as $relationship)
285
+        {
286 286
 			
287
-			// Check foreign key
288
-			if ($relationship->foreignKey)
289
-			{
290
-				$reverseRelationshipStub = "";
291
-				$functionName = '';
292
-				if ($relationship->type == "hasOne")
293
-					$functionName = strtolower($relationship->modelName);
294
-				else 
295
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
287
+            // Check foreign key
288
+            if ($relationship->foreignKey)
289
+            {
290
+                $reverseRelationshipStub = "";
291
+                $functionName = '';
292
+                if ($relationship->type == "hasOne")
293
+                    $functionName = strtolower($relationship->modelName);
294
+                else 
295
+                    $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
296 296
 				
297
-				if ($relationship->type == "belongsToMany") {
298
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
299
-					$reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub);
300
-					$reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub);
301
-					$reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
302
-					$reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub);
303
-					$reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304
-				}
305
-				else {
306
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
307
-					$reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308
-					$reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
309
-					$reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub);
310
-					$reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub);
311
-					$reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub);
312
-				}
297
+                if ($relationship->type == "belongsToMany") {
298
+                    $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
299
+                    $reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub);
300
+                    $reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub);
301
+                    $reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
302
+                    $reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub);
303
+                    $reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304
+                }
305
+                else {
306
+                    $reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
307
+                    $reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308
+                    $reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
309
+                    $reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub);
310
+                    $reverseRelationshipStub = str_replace('{{type}}', $relationship->type, $reverseRelationshipStub);
311
+                    $reverseRelationshipStub = str_replace('{{foreign_table}}', $functionName, $reverseRelationshipStub);
312
+                }
313 313
 					
314
-				$reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub);
314
+                $reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub);
315 315
 				
316
-				$functions .= $reverseRelationshipStub ;
316
+                $functions .= $reverseRelationshipStub ;
317 317
 
318
-				if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){
319
-					array_push($eagerArray, "'".$relationship->foreignKey->table."'");
320
-				}
321
-			}
318
+                if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){
319
+                    array_push($eagerArray, "'".$relationship->foreignKey->table."'");
320
+                }
321
+            }
322 322
 
323 323
 			
324
-		}
324
+        }
325 325
 
326
-		$this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub);
326
+        $this->stub = str_replace('{{reverseRelationship}}', $functions, $this->stub);
327 327
 
328 328
 
329
-		return $this;
330
-	}
329
+        return $this;
330
+    }
331 331
 
332 332
 
333
-	/**
334
-	 * Replace eager code for each foreing key with eager = true 
335
-	 *
336
-	 * @return $this
337
-	 */
338
-	private function replaceEagerCode()
339
-	{
340
-		$storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
341
-		$eagerConditions = $eagerJoins = '';
333
+    /**
334
+     * Replace eager code for each foreing key with eager = true 
335
+     *
336
+     * @return $this
337
+     */
338
+    private function replaceEagerCode()
339
+    {
340
+        $storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
341
+        $eagerConditions = $eagerJoins = '';
342 342
 
343
-		$storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
344
-		$updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
345
-		$rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
346
-		$useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
347
-		$joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
343
+        $storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
344
+        $updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
345
+        $rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
346
+        $useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
347
+        $joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
348 348
 
349
-		foreach ($this->modelData->fields as $field)
350
-		{
349
+        foreach ($this->modelData->fields as $field)
350
+        {
351 351
 			
352
-			// Check foreign key
353
-			if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
354
-			{
355
-
356
-				$storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
357
-				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
358
-				$ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
359
-				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
360
-				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
361
-
362
-				// search eager fields
363
-				$foreignModelData = $this->getModelData($field->foreignKey->table);
364
-				$foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
365
-				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
366
-				$eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
367
-				$eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
368
-				$eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
369
-				$eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
370
-				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
371
-			}
372
-
373
-		}
374
-
375
-		$this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
376
-		$this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
377
-		$this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
378
-		$this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
379
-		$this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
380
-		$this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
381
-		$this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
352
+            // Check foreign key
353
+            if ($field->foreignKey && isset($field->foreignKey->eager) && $field->foreignKey->eager)
354
+            {
355
+
356
+                $storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
357
+                $updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
358
+                $ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
359
+                $useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
360
+                $eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
361
+
362
+                // search eager fields
363
+                $foreignModelData = $this->getModelData($field->foreignKey->table);
364
+                $foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
365
+                $foreignControllerCompiler->setEagerTable($this->modelData->tableName);
366
+                $eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
367
+                $eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
368
+                $eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
369
+                $eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
370
+                $ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
371
+            }
372
+
373
+        }
374
+
375
+        $this->stub = str_replace('{{store_eager_objects}}', $storeCommands, $this->stub);
376
+        $this->stub = str_replace('{{update_eager_objects}}', $updateCommands, $this->stub);
377
+        $this->stub = str_replace('{{rules_eager}}', $ruleCommands, $this->stub);
378
+        $this->stub = str_replace('{{eager_use_classes}}', $useCommands, $this->stub);
379
+        $this->stub = str_replace('{{eager_joins}}', $eagerJoins, $this->stub);
380
+        $this->stub = str_replace('{{eager_conditions}}', $eagerConditions, $this->stub);
381
+        $this->stub = str_replace('{{eager_table}}', $this->eagerTable, $this->stub);
382 382
 		
383 383
 
384 384
 
385
-		return $this;
386
-	}
385
+        return $this;
386
+    }
387 387
 
388
-	/**
389
-	 * replace relationship tables
390
-	 *
391
-	 * @return $this
392
-	 */
393
-	public function replaceRelationshipTables() {
388
+    /**
389
+     * replace relationship tables
390
+     *
391
+     * @return $this
392
+     */
393
+    public function replaceRelationshipTables() {
394 394
 
395
-		$functions = "";
396
-		$functionsCall = "";
397
-		$removeAll = "";
398
-		$removeAllCall = "";
399
-		$includes = "";
400
-		$joins = "";
401
-		$joinSorts = "";
395
+        $functions = "";
396
+        $functionsCall = "";
397
+        $removeAll = "";
398
+        $removeAllCall = "";
399
+        $includes = "";
400
+        $joins = "";
401
+        $joinSorts = "";
402 402
 
403
-		$method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php');
403
+        $method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php');
404 404
 
405
-		foreach ($this->modelData->reverseRelationships as $relationship) {
405
+        foreach ($this->modelData->reverseRelationships as $relationship) {
406 406
 
407
-			if ($relationship->type == "belongsToMany") {
408
-				$relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
409
-				$relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
407
+            if ($relationship->type == "belongsToMany") {
408
+                $relatedTablePluralized = CamelCase::pluralize($relationship->relatedTable);
409
+                $relatedTablePluralizedUc = CamelCase::pluralize(CamelCase::convertToCamelCase($relationship->relatedTable));
410 410
 
411
-				$replacedMethod = '';
412
-				$replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
413
-				$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
414
-				$replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
415
-				$replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
416
-				$replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
417
-				$replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
418
-				$replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
411
+                $replacedMethod = '';
412
+                $replacedMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $method);
413
+                $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
414
+                $replacedMethod = str_replace('{{related_table_pl}}', $relatedTablePluralized, $replacedMethod);
415
+                $replacedMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $replacedMethod);
416
+                $replacedMethod = str_replace('{{related_field}}', $relationship->relatedField, $replacedMethod);
417
+                $replacedMethod = str_replace('{{foreign_table_lw}}', strtolower($relationship->modelName), $replacedMethod);
418
+                $replacedMethod = str_replace('{{foreign_table}}', $relationship->modelName, $replacedMethod);
419 419
 
420
-				$functions .= $replacedMethod;
420
+                $functions .= $replacedMethod;
421 421
 
422
-				$methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
423
-				$methodCall .= "\n\t\t\t";
424
-				$methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
425
-				$methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
426
-				$methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
427
-				$methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
422
+                $methodCall = 'if (array_key_exists(\'{{related_table_pl}}\', $vars))';
423
+                $methodCall .= "\n\t\t\t";
424
+                $methodCall .= '$this->save{{related_table_pl_uc}}($vars, ${{class_name_lw}});';
425
+                $methodCall = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $methodCall);
426
+                $methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
427
+                $methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
428 428
 
429
-				$functionsCall .= $methodCall . "\n\t\t";
429
+                $functionsCall .= $methodCall . "\n\t\t";
430 430
 				
431
-				$removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
432
-				$removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
433
-				$removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
434
-				$removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
435
-				$removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
431
+                $removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
432
+                $removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
433
+                $removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
434
+                $removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
435
+                $removeAllMethod = str_replace('{{foreign_table_lw_pl}}', CamelCase::pluralize(strtolower($relationship->modelName)), $removeAllMethod);
436 436
 				
437
-				$removeAll .= $removeAllMethod;
437
+                $removeAll .= $removeAllMethod;
438 438
 
439
-				$removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
440
-				$removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
441
-				$removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
439
+                $removeAllCallMethod = '$this->deleteAll{{related_table_pl_uc}}(${{class_name_lw}}[\'id\']);';
440
+                $removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
441
+                $removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
442 442
 				
443
-				$removeAllCall .= $removeAllCallMethod . "\n\t\t";
443
+                $removeAllCall .= $removeAllCallMethod . "\n\t\t";
444 444
 
445
-				$joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
446
-				$joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
447
-				$joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
448
-				$joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
449
-				$joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
450
-				$joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
451
-				$joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
445
+                $joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
446
+                $joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
447
+                $joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
448
+                $joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
449
+                $joinRelationshipTableStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $joinRelationshipTableStub);
450
+                $joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
451
+                $joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
452 452
 
453
-				$joins .= $joinRelationshipTableStub . "\n";
453
+                $joins .= $joinRelationshipTableStub . "\n";
454 454
 
455
-				$use = 'use App\Models\{{foreign_table}};';
456
-				$use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
455
+                $use = 'use App\Models\{{foreign_table}};';
456
+                $use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
457 457
 
458
-				$includes .= $use . "\n";
459
-			}
460
-		}
458
+                $includes .= $use . "\n";
459
+            }
460
+        }
461 461
 
462
-		$this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
462
+        $this->stub = str_replace('{{relationship_tables_store}}', $functions, $this->stub);
463 463
 
464
-		$this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
464
+        $this->stub = str_replace('{{relationship_tables_call}}', $functionsCall, $this->stub);
465 465
 
466
-		$this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
466
+        $this->stub = str_replace('{{remove_relationship_objects}}', $removeAll, $this->stub);
467 467
 
468
-		$this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
468
+        $this->stub = str_replace('{{remove_relationship_objects_call}}', $removeAllCall, $this->stub);
469 469
 
470
-		$this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
470
+        $this->stub = str_replace('{{relationship_tables_classes}}', $includes, $this->stub);
471 471
 
472
-		$this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
472
+        $this->stub = str_replace('{{relationship_tables_joins}}', $joins, $this->stub);
473 473
 
474 474
 		
475 475
 		
476
-		return $this;
476
+        return $this;
477 477
 
478
-	}
478
+    }
479 479
 
480 480
 
481
-	/**
482
-	 * Replace search conditions
483
-	 *
484
-	 * @return $this
485
-	 */
486
-	private function replaceSearchConditions(){
481
+    /**
482
+     * Replace search conditions
483
+     *
484
+     * @return $this
485
+     */
486
+    private function replaceSearchConditions(){
487 487
 
488
-		$searchConditions = $this->getSearchConditions();
488
+        $searchConditions = $this->getSearchConditions();
489 489
 
490
-		$this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
490
+        $this->stub = str_replace('{{conditions}}', $searchConditions, $this->stub);
491 491
 
492
-		return $this;
493
-	}
492
+        return $this;
493
+    }
494 494
 
495
-	/**
496
-	 * get search conditions
497
-	 *
498
-	 * @return $this
499
-	 */
500
-	public function getSearchConditions(){
495
+    /**
496
+     * get search conditions
497
+     *
498
+     * @return $this
499
+     */
500
+    public function getSearchConditions(){
501 501
 
502
-		$fieldConditions = '';
502
+        $fieldConditions = '';
503 503
 
504
-		$searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
504
+        $searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
505 505
 
506
-		foreach ($this->modelData->fields as $field)
507
-		{
506
+        foreach ($this->modelData->fields as $field)
507
+        {
508 508
 
509
-			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
509
+            $fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
510 510
 
511
-		}
511
+        }
512 512
 
513
-		// replace all field conditions
514
-		$searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
513
+        // replace all field conditions
514
+        $searchConditions = str_replace('{{field_conditions}}', $fieldConditions, $searchConditions);
515 515
 
516
-		// replace table name
517
-		$searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
516
+        // replace table name
517
+        $searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
518 518
 
519
-		return $searchConditions ;
519
+        return $searchConditions ;
520 520
 
521
-	}
521
+    }
522 522
 
523
-	/**
524
-	 * get search conditions stub by db type
525
-	 *
526
-	 * @param string $field
527
-	 *
528
-	 * @return $this
529
-	 */
530
-	private $conditionsStub = [];
531
-	private function getConditionStubByField($field){
523
+    /**
524
+     * get search conditions stub by db type
525
+     *
526
+     * @param string $field
527
+     *
528
+     * @return $this
529
+     */
530
+    private $conditionsStub = [];
531
+    private function getConditionStubByField($field){
532 532
 		
533
-		if($field->index == 'primary'){
534
-			$dbType = 'primary' ;
535
-		}
536
-		elseif($field->foreignKey){
537
-			$dbType = 'primary' ;
538
-		}
539
-		elseif($field->type->db == 'enum'){
540
-			$dbType = 'primary' ;
541
-		}
542
-		elseif($field->type->db == 'boolean'){
543
-			$dbType = 'primary' ;
544
-		}
545
-		elseif($field->type->db == 'text'){
546
-			$dbType = 'string' ;
547
-		}
548
-		else {
549
-			$dbType = $field->type->db ;
550
-		}
551
-
552
-		if(array_key_exists($dbType, $this->conditionsStub)){
553
-			return $this->conditionsStub[$dbType];
554
-		}
555
-		else {
556
-			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
557
-
558
-			return $this->conditionsStub[$dbType];
559
-		}
560
-	}
561
-
562
-	public function replaceSortConditions()	{
563
-		$joinSorts = '';
564
-
565
-		foreach ($this->modelData->fields as $field) {
566
-			if($field->foreignKey){
567
-				$joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
568
-				$joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
569
-				$joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
570
-				$joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
571
-				$joinSorts .= $joinSortStub;
572
-
573
-			}
533
+        if($field->index == 'primary'){
534
+            $dbType = 'primary' ;
535
+        }
536
+        elseif($field->foreignKey){
537
+            $dbType = 'primary' ;
538
+        }
539
+        elseif($field->type->db == 'enum'){
540
+            $dbType = 'primary' ;
541
+        }
542
+        elseif($field->type->db == 'boolean'){
543
+            $dbType = 'primary' ;
544
+        }
545
+        elseif($field->type->db == 'text'){
546
+            $dbType = 'string' ;
547
+        }
548
+        else {
549
+            $dbType = $field->type->db ;
550
+        }
551
+
552
+        if(array_key_exists($dbType, $this->conditionsStub)){
553
+            return $this->conditionsStub[$dbType];
554
+        }
555
+        else {
556
+            $this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
557
+
558
+            return $this->conditionsStub[$dbType];
559
+        }
560
+    }
561
+
562
+    public function replaceSortConditions()	{
563
+        $joinSorts = '';
564
+
565
+        foreach ($this->modelData->fields as $field) {
566
+            if($field->foreignKey){
567
+                $joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
568
+                $joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
569
+                $joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
570
+                $joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
571
+                $joinSorts .= $joinSortStub;
572
+
573
+            }
574 574
 			
575 575
 	
576 576
 			
577
-		}
577
+        }
578 578
 		
579 579
 
580
-		$this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
580
+        $this->stub = str_replace('{{relationship_tables_joins_sort}}', $joinSorts, $this->stub);
581 581
 
582
-		return $this;
583
-	}
582
+        return $this;
583
+    }
584 584
 
585 585
 
586 586
 
587
-	/**
588
-	 * replace reverse relationships
589
-	 *
590
-	 * @return $this
591
-	 */
592
-	public function replaceReverseRelationshipsFunctions(){
587
+    /**
588
+     * replace reverse relationships
589
+     *
590
+     * @return $this
591
+     */
592
+    public function replaceReverseRelationshipsFunctions(){
593 593
 
594
-		$functions = '';
594
+        $functions = '';
595 595
 
596
-		$method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php');
596
+        $method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php');
597 597
 
598
-		foreach ($this->modelData->reverseRelationships as $relationship)
599
-		{
600
-			$functionName = '';
601
-			if ($relationship->type == "hasOne")
602
-				$functionName = strtolower($relationship->modelName);
603
-			elseif ($relationship->type == "belongsToMany") 
604
-				$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
605
-			else 
606
-				$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
598
+        foreach ($this->modelData->reverseRelationships as $relationship)
599
+        {
600
+            $functionName = '';
601
+            if ($relationship->type == "hasOne")
602
+                $functionName = strtolower($relationship->modelName);
603
+            elseif ($relationship->type == "belongsToMany") 
604
+                $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
605
+            else 
606
+                $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
607 607
 
608
-			$replacedMethod = '';
609
-			$replacedMethod = str_replace('{{function_name}}', $functionName, $method);
610
-			$replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
611
-			$replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
608
+            $replacedMethod = '';
609
+            $replacedMethod = str_replace('{{function_name}}', $functionName, $method);
610
+            $replacedMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $replacedMethod);
611
+            $replacedMethod = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $replacedMethod);
612 612
 
613
-			$functions .= $replacedMethod;
614
-		}
613
+            $functions .= $replacedMethod;
614
+        }
615 615
 
616
-		$this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub);
616
+        $this->stub = str_replace('{{reverseRelationshipFunctions}}', $functions, $this->stub);
617 617
 
618
-		return $this;
618
+        return $this;
619 619
 
620
-	}
620
+    }
621 621
 
622 622
 
623
-	/**
624
-	 * replace checkbox fields
625
-	 *
626
-	 * @return $this
627
-	 */
628
-	public function replaceCheckbox(){
623
+    /**
624
+     * replace checkbox fields
625
+     *
626
+     * @return $this
627
+     */
628
+    public function replaceCheckbox(){
629 629
 
630
-		$method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php');
631
-		$key = false;
630
+        $method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php');
631
+        $key = false;
632 632
 
633
-		$method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
634
-		$method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
635
-		$method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
636
-		$this->stub = str_replace('{{checkbox}}', $method, $this->stub);
633
+        $method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
634
+        $method = str_replace('{{class_name}}', ucwords($this->modelData->tableName), $method);
635
+        $method = str_replace('{{model_name}}', $this->modelData->modelName, $method);
636
+        $this->stub = str_replace('{{checkbox}}', $method, $this->stub);
637 637
 
638
-		return $this;
638
+        return $this;
639 639
 
640
-	}
640
+    }
641 641
 
642 642
 
643
-	/**
644
-	 * Replace simple filter
645
-	 *
646
-	 * @return $this
647
-	 */
648
-	private function replaceSimpleFilter(){
649
-		$i = 0;
643
+    /**
644
+     * Replace simple filter
645
+     *
646
+     * @return $this
647
+     */
648
+    private function replaceSimpleFilter(){
649
+        $i = 0;
650 650
 
651
-		$stubSimpleFilter = '';
651
+        $stubSimpleFilter = '';
652 652
 
653
-		foreach ($this->modelData->fields as $field)
654
-		{
655
-			//var_dump($field->name);
653
+        foreach ($this->modelData->fields as $field)
654
+        {
655
+            //var_dump($field->name);
656 656
 			
657
-			if($field->index == 'primary'){
658
-				$dbType = 'primaryKey' ;
659
-			}
660
-			elseif($field->foreignKey){
661
-				$dbType = 'primary' ;
662
-			}
663
-			elseif($field->type->db == 'enum'){
664
-				$dbType = 'primary' ;
665
-			}
666
-			elseif($field->type->db == 'boolean'){
667
-				$dbType = 'primary' ;
668
-			}
669
-			elseif($field->type->db == 'text'){
670
-				$dbType = 'string' ;
671
-			}
672
-			else {
673
-				$dbType = $field->type->db ;
674
-			}
657
+            if($field->index == 'primary'){
658
+                $dbType = 'primaryKey' ;
659
+            }
660
+            elseif($field->foreignKey){
661
+                $dbType = 'primary' ;
662
+            }
663
+            elseif($field->type->db == 'enum'){
664
+                $dbType = 'primary' ;
665
+            }
666
+            elseif($field->type->db == 'boolean'){
667
+                $dbType = 'primary' ;
668
+            }
669
+            elseif($field->type->db == 'text'){
670
+                $dbType = 'string' ;
671
+            }
672
+            else {
673
+                $dbType = $field->type->db ;
674
+            }
675 675
 			
676
-			if($dbType == 'primaryKey')
677
-			{
678
-				$stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
679
-			}
680
-
681
-			if($dbType == 'primary')
682
-			{
683
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
684
-			}
685
-
686
-			if($dbType == 'string')
687
-			{
688
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
689
-			}
690
-
691
-			if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
692
-			{
693
-				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
694
-			}
695
-
696
-		}
697
-		$stubSimpleFilter .= ';';
698
-		$this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
699
-
700
-		return $this;
701
-	}
676
+            if($dbType == 'primaryKey')
677
+            {
678
+                $stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
679
+            }
680
+
681
+            if($dbType == 'primary')
682
+            {
683
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
684
+            }
685
+
686
+            if($dbType == 'string')
687
+            {
688
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
689
+            }
690
+
691
+            if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
692
+            {
693
+                $stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
694
+            }
695
+
696
+        }
697
+        $stubSimpleFilter .= ';';
698
+        $this->stub = str_replace('{{simple_filter}}', $stubSimpleFilter, $this->stub);
699
+
700
+        return $this;
701
+    }
702 702
 }
703 703
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@  discard block
 block discarded – undo
12 12
 class ModelCompiler extends AbstractCompiler
13 13
 {
14 14
 	protected $cachePrefix 	= 'model_';
15
-	protected $stubFilename = 'Model/Model.php' ;
15
+	protected $stubFilename = 'Model/Model.php';
16 16
 
17 17
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18 18
 	{
19 19
 		if ($stubName)
20 20
 			$this->stubFilename = $stubName;
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/Api/';
22 22
 		parent::__construct($scaffolderConfig, $modelData);
23 23
 	}
24 24
 
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	protected function getOutputFilename()
60 60
 	{
61
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->models) ;
61
+		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->models);
62 62
 
63
-		return $folder .  $this->modelName . '.php';
63
+		return $folder.$this->modelName.'.php';
64 64
 	}
65 65
 
66 66
 	
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 
92 92
 		foreach ($this->modelData->fields as $field)
93 93
 		{
94
-			if($field->index == "primary")
95
-				continue ;
96
-			if($this->modelData->timeStamps && $field->name == "created_at")
97
-				continue ;
98
-			if($this->modelData->timeStamps && $field->name == "updated_at")
99
-				continue ;
94
+			if ($field->index == "primary")
95
+				continue;
96
+			if ($this->modelData->timeStamps && $field->name == "created_at")
97
+				continue;
98
+			if ($this->modelData->timeStamps && $field->name == "updated_at")
99
+				continue;
100 100
 
101 101
 			if ($firstIteration)
102 102
 			{
103
-				$fields .= sprintf("'%s'," . PHP_EOL, $field->name);
103
+				$fields .= sprintf("'%s',".PHP_EOL, $field->name);
104 104
 				$firstIteration = false;
105 105
 			}
106 106
 			else
107 107
 			{
108
-				$fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
108
+				$fields .= sprintf("\t\t'%s',".PHP_EOL, $field->name);
109 109
 			}
110 110
 		}
111 111
 
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
 		$arrays = '';
121 121
 		
122 122
 		foreach ($this->modelData->fields as $field) {
123
-			$enumStub = File::get($this->stubsDirectory . '/Model/ModelEnum.php');
123
+			$enumStub = File::get($this->stubsDirectory.'/Model/ModelEnum.php');
124 124
 
125 125
 			if ($field->type->db == "enum") {
126 126
 				$items = '';
127 127
 				
128 128
 				foreach ($field->options as $key => $option) {
129
-					$items .= "'" . $option . "'";
129
+					$items .= "'".$option."'";
130 130
 					if ($key < (count($field->options) - 1))
131 131
 						$items .= ", ";
132 132
 
@@ -160,25 +160,25 @@  discard block
 block discarded – undo
160 160
 
161 161
 		foreach ($this->modelData->fields as $field)
162 162
 		{
163
-			if($field->index == "primary")
164
-				continue ;
165
-			if($this->modelData->timeStamps && $field->name == "created_at")
166
-				continue ;
167
-			if($this->modelData->timeStamps && $field->name == "updated_at")
168
-				continue ;
163
+			if ($field->index == "primary")
164
+				continue;
165
+			if ($this->modelData->timeStamps && $field->name == "created_at")
166
+				continue;
167
+			if ($this->modelData->timeStamps && $field->name == "updated_at")
168
+				continue;
169 169
 
170 170
 			if ($firstIteration)
171 171
 			{
172
-				$fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
172
+				$fields .= sprintf("'%s' => '%s',".PHP_EOL, $field->name, $field->validations);
173 173
 				$firstIteration = false;
174 174
 			}
175 175
 			else
176 176
 			{
177
-				$fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
177
+				$fields .= sprintf("\t\t\t'%s' => '%s',".PHP_EOL, $field->name, $field->validations);
178 178
 			}
179 179
 		}
180 180
 
181
-		$fields = str_replace('unique','unique:'.$this->modelData->tableName,$fields);
181
+		$fields = str_replace('unique', 'unique:'.$this->modelData->tableName, $fields);
182 182
 		//var_dump($fields);
183 183
 
184 184
 		$this->stub = str_replace('{{validations}}', $fields, $this->stub);
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 */
193 193
 	private function setTimeStamps()
194 194
 	{
195
-		if($this->modelData->timeStamps)
195
+		if ($this->modelData->timeStamps)
196 196
 		{
197 197
 			$this->stub = str_replace('{{timestamps}}', ' ', $this->stub);
198 198
 		} else {
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	 */
209 209
 	private function setPrimaryKey()
210 210
 	{
211
-		$primaryKey = '// Using default primary key' . PHP_EOL;
211
+		$primaryKey = '// Using default primary key'.PHP_EOL;
212 212
 
213
-		$field = $this->getPrimaryKeyField() ;
213
+		$field = $this->getPrimaryKeyField();
214 214
 
215
-		$primaryKey = 'protected $primaryKey = \'' . $field->name . '\';' . PHP_EOL;
215
+		$primaryKey = 'protected $primaryKey = \''.$field->name.'\';'.PHP_EOL;
216 216
 
217 217
 		$this->stub = str_replace('{{primaryAttribute}}', $primaryKey, $this->stub);
218 218
 
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
 				$functionName = $field->foreignKey->table;
242 242
 
243 243
 				if ($field->foreignKey->relationship == "belongsTo") {
244
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsTo.php');
244
+					$belongsToOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsTo.php');
245 245
 					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246 246
 					$belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247 247
 					$belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248 248
 				}
249 249
 				elseif ($field->foreignKey->relationship == "belongsToMany") {
250
-					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
250
+					$belongsToOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsToMany.php');
251 251
 					$functionName = CamelCase::pluralize($field->foreignKey->table);
252 252
 					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
253 253
 					$belongsToStub = str_replace('{{foreign_key}}', $field->name, $belongsToStub);
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 				$belongsToStub = str_replace('{{foreign_table}}', $functionName, $belongsToStub);
259 259
 				$belongsToStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $belongsToStub);
260 260
 				
261
-				$functions .= $belongsToStub ;
261
+				$functions .= $belongsToStub;
262 262
 
263
-				if(isset($field->foreignKey->eager) && $field->foreignKey->eager){
263
+				if (isset($field->foreignKey->eager) && $field->foreignKey->eager) {
264 264
 					array_push($eagerArray, "'".$field->foreignKey->table."'");
265 265
 				}
266 266
 			}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 
271 271
 		$this->stub = str_replace('{{belongsTo}}', $functions, $this->stub);
272 272
 
273
-		$this->stub = str_replace('{{eager}}', join("," , $eagerArray) , $this->stub);
273
+		$this->stub = str_replace('{{eager}}', join(",", $eagerArray), $this->stub);
274 274
 
275 275
 		return $this;
276 276
 	}
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
296 296
 				
297 297
 				if ($relationship->type == "belongsToMany") {
298
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
298
+					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory.'/Model/ModelBelongsToMany.php');
299 299
 					$reverseRelationshipStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($relationship->relatedTable), $reverseRelationshipOriginalStub);
300 300
 					$reverseRelationshipStub = str_replace('{{foreign_key}}', $relationship->foreignKey, $reverseRelationshipStub);
301 301
 					$reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 					$reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304 304
 				}
305 305
 				else {
306
-					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
306
+					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory.'/Model/ModelReverseRelationship.php');
307 307
 					$reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308 308
 					$reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
309 309
 					$reverseRelationshipStub = str_replace('{{foreign_field}}', $relationship->localKey, $reverseRelationshipStub);
@@ -313,9 +313,9 @@  discard block
 block discarded – undo
313 313
 					
314 314
 				$reverseRelationshipStub = str_replace('{{model_namespace}}', $this->scaffolderConfig->generator->namespaces->models, $reverseRelationshipStub);
315 315
 				
316
-				$functions .= $reverseRelationshipStub ;
316
+				$functions .= $reverseRelationshipStub;
317 317
 
318
-				if(isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager){
318
+				if (isset($relationship->foreignKey->eager) && $relationship->foreignKey->eager) {
319 319
 					array_push($eagerArray, "'".$relationship->foreignKey->table."'");
320 320
 				}
321 321
 			}
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 		$storeCommands = $updateCommands = $ruleCommands = $useCommands = '';
341 341
 		$eagerConditions = $eagerJoins = '';
342 342
 
343
-		$storeEagerStubOriginal = File::get($this->stubsDirectory . 'StoreEager.php');
344
-		$updateEagerStubOriginal = File::get($this->stubsDirectory . 'UpdateEager.php');
345
-		$rulesEagerStubOriginal = File::get($this->stubsDirectory . 'RulesEager.php');
346
-		$useEagerStubOriginal = File::get($this->stubsDirectory . 'UseEager.php');
347
-		$joinEagerStubOriginal = File::get($this->stubsDirectory . 'SearchConditions/JoinEager.php');
343
+		$storeEagerStubOriginal = File::get($this->stubsDirectory.'StoreEager.php');
344
+		$updateEagerStubOriginal = File::get($this->stubsDirectory.'UpdateEager.php');
345
+		$rulesEagerStubOriginal = File::get($this->stubsDirectory.'RulesEager.php');
346
+		$useEagerStubOriginal = File::get($this->stubsDirectory.'UseEager.php');
347
+		$joinEagerStubOriginal = File::get($this->stubsDirectory.'SearchConditions/JoinEager.php');
348 348
 
349 349
 		foreach ($this->modelData->fields as $field)
350 350
 		{
@@ -354,20 +354,20 @@  discard block
 block discarded – undo
354 354
 			{
355 355
 
356 356
 				$storeCommands 	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $storeEagerStubOriginal));
357
-				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal)) ;
358
-				$ruleCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal)) ;
359
-				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal)) ;
360
-				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal) ;
357
+				$updateCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $updateEagerStubOriginal));
358
+				$ruleCommands .= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $rulesEagerStubOriginal));
359
+				$useCommands	.= str_replace('{{foreign_model_name}}', CamelCase::convertToCamelCase($field->foreignKey->table), $this->replaceForeingStrings($field, $useEagerStubOriginal));
360
+				$eagerJoins		.= $this->replaceForeingStrings($field, $joinEagerStubOriginal);
361 361
 
362 362
 				// search eager fields
363 363
 				$foreignModelData = $this->getModelData($field->foreignKey->table);
364 364
 				$foreignControllerCompiler = new ControllerCompiler($this->scaffolderConfig, $foreignModelData);
365 365
 				$foreignControllerCompiler->setEagerTable($this->modelData->tableName);
366
-				$eagerConditions 	.= $foreignControllerCompiler->getSearchConditions();
366
+				$eagerConditions .= $foreignControllerCompiler->getSearchConditions();
367 367
 				$eagerUniqueRules = $foreignControllerCompiler->getEagerUniqueRules();
368 368
 				$eagerUniqueRules = str_replace("{{class_name_lw}}", strtolower($this->modelName), $eagerUniqueRules);
369 369
 				$eagerUniqueRules = str_replace("{{field}}", $field->name, $eagerUniqueRules);
370
-				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands) ;
370
+				$ruleCommands = str_replace('{{unique_eager_rules}}', $eagerUniqueRules, $ruleCommands);
371 371
 			}
372 372
 
373 373
 		}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		$joins = "";
401 401
 		$joinSorts = "";
402 402
 
403
-		$method = File::get($this->stubsDirectory . '/Model/ModelRelationshipTable.php');
403
+		$method = File::get($this->stubsDirectory.'/Model/ModelRelationshipTable.php');
404 404
 
405 405
 		foreach ($this->modelData->reverseRelationships as $relationship) {
406 406
 
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 				$methodCall = str_replace('{{related_table_pl}}', $relatedTablePluralized, $methodCall);
427 427
 				$methodCall = str_replace('{{class_name_lw}}', $this->modelData->tableName, $methodCall);
428 428
 
429
-				$functionsCall .= $methodCall . "\n\t\t";
429
+				$functionsCall .= $methodCall."\n\t\t";
430 430
 				
431
-				$removeAllMethod = File::get($this->stubsDirectory . '/Controller/ControllerRemoveAll.php');
431
+				$removeAllMethod = File::get($this->stubsDirectory.'/Controller/ControllerRemoveAll.php');
432 432
 				$removeAllMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllMethod);
433 433
 				$removeAllMethod = str_replace('{{foreign_key}}', $relationship->foreignKey, $removeAllMethod);
434 434
 				$removeAllMethod = str_replace('{{foreign_table}}', $relationship->modelName, $removeAllMethod);
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 				$removeAllCallMethod = str_replace('{{related_table_pl_uc}}', $relatedTablePluralizedUc, $removeAllCallMethod);
441 441
 				$removeAllCallMethod = str_replace('{{class_name_lw}}', $this->modelData->tableName, $removeAllCallMethod);
442 442
 				
443
-				$removeAllCall .= $removeAllCallMethod . "\n\t\t";
443
+				$removeAllCall .= $removeAllCallMethod."\n\t\t";
444 444
 
445
-				$joinRelationshipTableStub = File::get($this->stubsDirectory . 'SearchConditions/joinRelationshipTable.php');
445
+				$joinRelationshipTableStub = File::get($this->stubsDirectory.'SearchConditions/joinRelationshipTable.php');
446 446
 				$joinRelationshipTableStub = str_replace('{{class_name_lw}}', $this->modelData->tableName, $joinRelationshipTableStub);
447 447
 				$joinRelationshipTableStub = str_replace('{{related_table_pl}}', $relatedTablePluralized, $joinRelationshipTableStub);
448 448
 				$joinRelationshipTableStub = str_replace('{{related_table}}', CamelCase::convertToCamelCase($relationship->relatedTable), $joinRelationshipTableStub);
@@ -450,12 +450,12 @@  discard block
 block discarded – undo
450 450
 				$joinRelationshipTableStub = str_replace('{{related_field}}', $relationship->relatedField, $joinRelationshipTableStub);
451 451
 				$joinRelationshipTableStub = str_replace('{{foreign_table}}', $relationship->tableName, $joinRelationshipTableStub);
452 452
 
453
-				$joins .= $joinRelationshipTableStub . "\n";
453
+				$joins .= $joinRelationshipTableStub."\n";
454 454
 
455 455
 				$use = 'use App\Models\{{foreign_table}};';
456 456
 				$use = str_replace('{{foreign_table}}', $relationship->modelName, $use);
457 457
 
458
-				$includes .= $use . "\n";
458
+				$includes .= $use."\n";
459 459
 			}
460 460
 		}
461 461
 
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 	 *
484 484
 	 * @return $this
485 485
 	 */
486
-	private function replaceSearchConditions(){
486
+	private function replaceSearchConditions() {
487 487
 
488 488
 		$searchConditions = $this->getSearchConditions();
489 489
 
@@ -497,16 +497,16 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 * @return $this
499 499
 	 */
500
-	public function getSearchConditions(){
500
+	public function getSearchConditions() {
501 501
 
502 502
 		$fieldConditions = '';
503 503
 
504
-		$searchConditions = File::get($this->stubsDirectory . '/SearchConditions/Conditions.php');
504
+		$searchConditions = File::get($this->stubsDirectory.'/SearchConditions/Conditions.php');
505 505
 
506 506
 		foreach ($this->modelData->fields as $field)
507 507
 		{
508 508
 
509
-			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field)) ;
509
+			$fieldConditions .= $this->replaceFieldStrings($field, $this->getConditionStubByField($field));
510 510
 
511 511
 		}
512 512
 
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
 		// replace table name
517 517
 		$searchConditions = str_replace('{{table_name}}', $this->modelData->tableName, $searchConditions);
518 518
 
519
-		return $searchConditions ;
519
+		return $searchConditions;
520 520
 
521 521
 	}
522 522
 
@@ -528,43 +528,43 @@  discard block
 block discarded – undo
528 528
 	 * @return $this
529 529
 	 */
530 530
 	private $conditionsStub = [];
531
-	private function getConditionStubByField($field){
531
+	private function getConditionStubByField($field) {
532 532
 		
533
-		if($field->index == 'primary'){
534
-			$dbType = 'primary' ;
533
+		if ($field->index == 'primary') {
534
+			$dbType = 'primary';
535 535
 		}
536
-		elseif($field->foreignKey){
537
-			$dbType = 'primary' ;
536
+		elseif ($field->foreignKey) {
537
+			$dbType = 'primary';
538 538
 		}
539
-		elseif($field->type->db == 'enum'){
540
-			$dbType = 'primary' ;
539
+		elseif ($field->type->db == 'enum') {
540
+			$dbType = 'primary';
541 541
 		}
542
-		elseif($field->type->db == 'boolean'){
543
-			$dbType = 'primary' ;
542
+		elseif ($field->type->db == 'boolean') {
543
+			$dbType = 'primary';
544 544
 		}
545
-		elseif($field->type->db == 'text'){
546
-			$dbType = 'string' ;
545
+		elseif ($field->type->db == 'text') {
546
+			$dbType = 'string';
547 547
 		}
548 548
 		else {
549
-			$dbType = $field->type->db ;
549
+			$dbType = $field->type->db;
550 550
 		}
551 551
 
552
-		if(array_key_exists($dbType, $this->conditionsStub)){
552
+		if (array_key_exists($dbType, $this->conditionsStub)) {
553 553
 			return $this->conditionsStub[$dbType];
554 554
 		}
555 555
 		else {
556
-			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
556
+			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory.'SearchConditions/'.ucwords($dbType).'.php'); ;
557 557
 
558 558
 			return $this->conditionsStub[$dbType];
559 559
 		}
560 560
 	}
561 561
 
562
-	public function replaceSortConditions()	{
562
+	public function replaceSortConditions() {
563 563
 		$joinSorts = '';
564 564
 
565 565
 		foreach ($this->modelData->fields as $field) {
566
-			if($field->foreignKey){
567
-				$joinSortStub = File::get($this->stubsDirectory . 'SearchConditions/JoinSort.php');
566
+			if ($field->foreignKey) {
567
+				$joinSortStub = File::get($this->stubsDirectory.'SearchConditions/JoinSort.php');
568 568
 				$joinSortStub = str_replace('{{field}}', $field->name, $joinSortStub);
569 569
 				$joinSortStub = str_replace('{{foreign_table}}', $field->foreignKey->table, $joinSortStub);
570 570
 				$joinSortStub = str_replace('{{foreign_key}}', $field->foreignKey->table, $joinSortStub);
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
 	 *
590 590
 	 * @return $this
591 591
 	 */
592
-	public function replaceReverseRelationshipsFunctions(){
592
+	public function replaceReverseRelationshipsFunctions() {
593 593
 
594 594
 		$functions = '';
595 595
 
596
-		$method = File::get($this->stubsDirectory . '/Model/ModelReverseRelationshipFunctions.php');
596
+		$method = File::get($this->stubsDirectory.'/Model/ModelReverseRelationshipFunctions.php');
597 597
 
598 598
 		foreach ($this->modelData->reverseRelationships as $relationship)
599 599
 		{
@@ -625,9 +625,9 @@  discard block
 block discarded – undo
625 625
 	 *
626 626
 	 * @return $this
627 627
 	 */
628
-	public function replaceCheckbox(){
628
+	public function replaceCheckbox() {
629 629
 
630
-		$method = File::get($this->stubsDirectory . '/Model/ModelCheckbox.php');
630
+		$method = File::get($this->stubsDirectory.'/Model/ModelCheckbox.php');
631 631
 		$key = false;
632 632
 
633 633
 		$method = str_replace('{{class_name_lw}}', $this->modelData->tableName, $method);
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	 *
646 646
 	 * @return $this
647 647
 	 */
648
-	private function replaceSimpleFilter(){
648
+	private function replaceSimpleFilter() {
649 649
 		$i = 0;
650 650
 
651 651
 		$stubSimpleFilter = '';
@@ -654,41 +654,41 @@  discard block
 block discarded – undo
654 654
 		{
655 655
 			//var_dump($field->name);
656 656
 			
657
-			if($field->index == 'primary'){
658
-				$dbType = 'primaryKey' ;
657
+			if ($field->index == 'primary') {
658
+				$dbType = 'primaryKey';
659 659
 			}
660
-			elseif($field->foreignKey){
661
-				$dbType = 'primary' ;
660
+			elseif ($field->foreignKey) {
661
+				$dbType = 'primary';
662 662
 			}
663
-			elseif($field->type->db == 'enum'){
664
-				$dbType = 'primary' ;
663
+			elseif ($field->type->db == 'enum') {
664
+				$dbType = 'primary';
665 665
 			}
666
-			elseif($field->type->db == 'boolean'){
667
-				$dbType = 'primary' ;
666
+			elseif ($field->type->db == 'boolean') {
667
+				$dbType = 'primary';
668 668
 			}
669
-			elseif($field->type->db == 'text'){
670
-				$dbType = 'string' ;
669
+			elseif ($field->type->db == 'text') {
670
+				$dbType = 'string';
671 671
 			}
672 672
 			else {
673
-				$dbType = $field->type->db ;
673
+				$dbType = $field->type->db;
674 674
 			}
675 675
 			
676
-			if($dbType == 'primaryKey')
676
+			if ($dbType == 'primaryKey')
677 677
 			{
678 678
 				$stubSimpleFilter .= '$query->where("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
679 679
 			}
680 680
 
681
-			if($dbType == 'primary')
681
+			if ($dbType == 'primary')
682 682
 			{
683 683
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
684 684
 			}
685 685
 
686
-			if($dbType == 'string')
686
+			if ($dbType == 'string')
687 687
 			{
688 688
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "LIKE", "%".$'.$this->modelData->tableName.'Conditions["'.$field->name.'"]."%")'.PHP_EOL;
689 689
 			}
690 690
 
691
-			if($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
691
+			if ($dbType == 'date' || $dbType == 'datetime' || $dbType == 'float' || $dbType == 'integer' || $dbType == 'number')
692 692
 			{
693 693
 				$stubSimpleFilter .= '->orWhere("'.$this->modelData->tableName.'.'.$field->name.'", "=", $'.$this->modelData->tableName.'Conditions["'.$field->name.'"])'.PHP_EOL;
694 694
 			}
Please login to merge, or discard this patch.
Braces   +51 added lines, -56 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 	public function __construct($scaffolderConfig, $modelData = null, $stubName = null)
18 18
 	{
19
-		if ($stubName)
20
-			$this->stubFilename = $stubName;
19
+		if ($stubName) {
20
+					$this->stubFilename = $stubName;
21
+		}
21 22
 		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22 23
 		parent::__construct($scaffolderConfig, $modelData);
23 24
 	}
@@ -91,19 +92,21 @@  discard block
 block discarded – undo
91 92
 
92 93
 		foreach ($this->modelData->fields as $field)
93 94
 		{
94
-			if($field->index == "primary")
95
-				continue ;
96
-			if($this->modelData->timeStamps && $field->name == "created_at")
97
-				continue ;
98
-			if($this->modelData->timeStamps && $field->name == "updated_at")
99
-				continue ;
95
+			if($field->index == "primary") {
96
+							continue ;
97
+			}
98
+			if($this->modelData->timeStamps && $field->name == "created_at") {
99
+							continue ;
100
+			}
101
+			if($this->modelData->timeStamps && $field->name == "updated_at") {
102
+							continue ;
103
+			}
100 104
 
101 105
 			if ($firstIteration)
102 106
 			{
103 107
 				$fields .= sprintf("'%s'," . PHP_EOL, $field->name);
104 108
 				$firstIteration = false;
105
-			}
106
-			else
109
+			} else
107 110
 			{
108 111
 				$fields .= sprintf("\t\t'%s'," . PHP_EOL, $field->name);
109 112
 			}
@@ -127,8 +130,9 @@  discard block
 block discarded – undo
127 130
 				
128 131
 				foreach ($field->options as $key => $option) {
129 132
 					$items .= "'" . $option . "'";
130
-					if ($key < (count($field->options) - 1))
131
-						$items .= ", ";
133
+					if ($key < (count($field->options) - 1)) {
134
+											$items .= ", ";
135
+					}
132 136
 
133 137
 				}
134 138
 
@@ -160,19 +164,21 @@  discard block
 block discarded – undo
160 164
 
161 165
 		foreach ($this->modelData->fields as $field)
162 166
 		{
163
-			if($field->index == "primary")
164
-				continue ;
165
-			if($this->modelData->timeStamps && $field->name == "created_at")
166
-				continue ;
167
-			if($this->modelData->timeStamps && $field->name == "updated_at")
168
-				continue ;
167
+			if($field->index == "primary") {
168
+							continue ;
169
+			}
170
+			if($this->modelData->timeStamps && $field->name == "created_at") {
171
+							continue ;
172
+			}
173
+			if($this->modelData->timeStamps && $field->name == "updated_at") {
174
+							continue ;
175
+			}
169 176
 
170 177
 			if ($firstIteration)
171 178
 			{
172 179
 				$fields .= sprintf("'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
173 180
 				$firstIteration = false;
174
-			}
175
-			else
181
+			} else
176 182
 			{
177 183
 				$fields .= sprintf("\t\t\t'%s' => '%s'," . PHP_EOL, $field->name, $field->validations);
178 184
 			}
@@ -245,8 +251,7 @@  discard block
 block discarded – undo
245 251
 					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
246 252
 					$belongsToStub = str_replace('{{field}}', $field->name, $belongsToStub);
247 253
 					$belongsToStub = str_replace('{{foreign_field}}', $field->foreignKey->field, $belongsToStub);
248
-				}
249
-				elseif ($field->foreignKey->relationship == "belongsToMany") {
254
+				} elseif ($field->foreignKey->relationship == "belongsToMany") {
250 255
 					$belongsToOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
251 256
 					$functionName = CamelCase::pluralize($field->foreignKey->table);
252 257
 					$belongsToStub = str_replace('{{foreign_model}}', CamelCase::convertToCamelCase($field->foreignKey->table), $belongsToOriginalStub);
@@ -289,10 +294,11 @@  discard block
 block discarded – undo
289 294
 			{
290 295
 				$reverseRelationshipStub = "";
291 296
 				$functionName = '';
292
-				if ($relationship->type == "hasOne")
293
-					$functionName = strtolower($relationship->modelName);
294
-				else 
295
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
297
+				if ($relationship->type == "hasOne") {
298
+									$functionName = strtolower($relationship->modelName);
299
+				} else {
300
+									$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
301
+				}
296 302
 				
297 303
 				if ($relationship->type == "belongsToMany") {
298 304
 					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelBelongsToMany.php');
@@ -301,8 +307,7 @@  discard block
 block discarded – undo
301 307
 					$reverseRelationshipStub = str_replace('{{table_name}}', $relationship->tableName, $reverseRelationshipStub);
302 308
 					$reverseRelationshipStub = str_replace('{{related_field}}', $relationship->relatedField, $reverseRelationshipStub);
303 309
 					$reverseRelationshipStub = str_replace('{{foreign_table}}', CamelCase::pluralize(strtolower($relationship->relatedTable)), $reverseRelationshipStub);
304
-				}
305
-				else {
310
+				} else {
306 311
 					$reverseRelationshipOriginalStub = File::get($this->stubsDirectory . '/Model/ModelReverseRelationship.php');
307 312
 					$reverseRelationshipStub = str_replace('{{foreign_model}}', $relationship->modelName, $reverseRelationshipOriginalStub);
308 313
 					$reverseRelationshipStub = str_replace('{{field}}', $relationship->foreignKey, $reverseRelationshipStub);
@@ -532,27 +537,21 @@  discard block
 block discarded – undo
532 537
 		
533 538
 		if($field->index == 'primary'){
534 539
 			$dbType = 'primary' ;
535
-		}
536
-		elseif($field->foreignKey){
540
+		} elseif($field->foreignKey){
537 541
 			$dbType = 'primary' ;
538
-		}
539
-		elseif($field->type->db == 'enum'){
542
+		} elseif($field->type->db == 'enum'){
540 543
 			$dbType = 'primary' ;
541
-		}
542
-		elseif($field->type->db == 'boolean'){
544
+		} elseif($field->type->db == 'boolean'){
543 545
 			$dbType = 'primary' ;
544
-		}
545
-		elseif($field->type->db == 'text'){
546
+		} elseif($field->type->db == 'text'){
546 547
 			$dbType = 'string' ;
547
-		}
548
-		else {
548
+		} else {
549 549
 			$dbType = $field->type->db ;
550 550
 		}
551 551
 
552 552
 		if(array_key_exists($dbType, $this->conditionsStub)){
553 553
 			return $this->conditionsStub[$dbType];
554
-		}
555
-		else {
554
+		} else {
556 555
 			$this->conditionsStub[$dbType] = File::get($this->stubsDirectory . 'SearchConditions/'. ucwords($dbType). '.php');;
557 556
 
558 557
 			return $this->conditionsStub[$dbType];
@@ -598,12 +597,13 @@  discard block
 block discarded – undo
598 597
 		foreach ($this->modelData->reverseRelationships as $relationship)
599 598
 		{
600 599
 			$functionName = '';
601
-			if ($relationship->type == "hasOne")
602
-				$functionName = strtolower($relationship->modelName);
603
-			elseif ($relationship->type == "belongsToMany") 
604
-				$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
605
-			else 
606
-				$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
600
+			if ($relationship->type == "hasOne") {
601
+							$functionName = strtolower($relationship->modelName);
602
+			} elseif ($relationship->type == "belongsToMany") {
603
+							$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
604
+			} else {
605
+							$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
606
+			}
607 607
 
608 608
 			$replacedMethod = '';
609 609
 			$replacedMethod = str_replace('{{function_name}}', $functionName, $method);
@@ -656,20 +656,15 @@  discard block
 block discarded – undo
656 656
 			
657 657
 			if($field->index == 'primary'){
658 658
 				$dbType = 'primaryKey' ;
659
-			}
660
-			elseif($field->foreignKey){
659
+			} elseif($field->foreignKey){
661 660
 				$dbType = 'primary' ;
662
-			}
663
-			elseif($field->type->db == 'enum'){
661
+			} elseif($field->type->db == 'enum'){
664 662
 				$dbType = 'primary' ;
665
-			}
666
-			elseif($field->type->db == 'boolean'){
663
+			} elseif($field->type->db == 'boolean'){
667 664
 				$dbType = 'primary' ;
668
-			}
669
-			elseif($field->type->db == 'text'){
665
+			} elseif($field->type->db == 'text'){
670 666
 				$dbType = 'string' ;
671
-			}
672
-			else {
667
+			} else {
673 668
 				$dbType = $field->type->db ;
674 669
 			}
675 670
 			
Please login to merge, or discard this patch.
src/Scaffolder/Compilers/Core/RouteCompiler.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * Compiles a group of routes.
46 46
 	 *
47 47
 	 * @param      $hash
48
-	 * @param null $extra
48
+	 * @param string $compiledRoutes
49 49
 	 *
50 50
 	 * @return mixed
51 51
 	 */
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * Get output filename
65 65
 	 *
66 66
 	 *
67
-	 * @return $this
67
+	 * @return string
68 68
 	 */
69 69
 	protected function getOutputFilename()
70 70
 	{
Please login to merge, or discard this patch.
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -10,165 +10,165 @@
 block discarded – undo
10 10
 
11 11
 class RouteCompiler extends AbstractCompiler
12 12
 {
13
-	protected $stubFilename = 'Routes.php' ;
13
+    protected $stubFilename = 'Routes.php' ;
14 14
 
15
-	protected $stubResourceFilename = 'ResourceRoute.php' ;
16
-	protected $stubResource  ;
15
+    protected $stubResourceFilename = 'ResourceRoute.php' ;
16
+    protected $stubResource  ;
17 17
 
18 18
 
19
-	public function __construct($scaffolderConfig, $modelData = null)
20
-	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
-		parent::__construct($scaffolderConfig, null);
19
+    public function __construct($scaffolderConfig, $modelData = null)
20
+    {
21
+        $this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
22
+        parent::__construct($scaffolderConfig, null);
23 23
 		
24
-		$this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
-	}
26
-
27
-	/**
28
-	 * Replace and store the Stub.
29
-	 *
30
-	 * @return string
31
-	 */
32
-	public function replaceAndStore(){}
33
-
34
-	/**
35
-	 * Compiles a resource.
36
-	 *
37
-	 * @param      $hash
38
-	 * @param null $extra
39
-	 *
40
-	 * @return string
41
-	 */
42
-	public function compile($extra = null) {}
43
-
44
-	/**
45
-	 * Compiles a group of routes.
46
-	 *
47
-	 * @param      $hash
48
-	 * @param null $extra
49
-	 *
50
-	 * @return mixed
51
-	 */
52
-	public function compileGroup($compiledRoutes)
53
-	{
54
-
55
-		$this->replaceRoutes($compiledRoutes)
56
-			->replaceRoutePrefix()
57
-			->store(new FileToCompile(null, null));
58
-
59
-		return $this->stub;
60
-	}
61
-
62
-
63
-	/**
64
-	 * Get output filename
65
-	 *
66
-	 *
67
-	 * @return $this
68
-	 */
69
-	protected function getOutputFilename()
70
-	{
71
-		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes);
72
-
73
-		return $folder  . 'routes.php';
74
-	}
75
-
76
-
77
-	/**
78
-	 * Replace the resource.
79
-	 *
80
-	 * @param $this->modelName
81
-	 *
82
-	 * @return string routeStub
83
-	 */
84
-	public function replaceResource($modelData)
85
-	{
24
+        $this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
25
+    }
26
+
27
+    /**
28
+     * Replace and store the Stub.
29
+     *
30
+     * @return string
31
+     */
32
+    public function replaceAndStore(){}
33
+
34
+    /**
35
+     * Compiles a resource.
36
+     *
37
+     * @param      $hash
38
+     * @param null $extra
39
+     *
40
+     * @return string
41
+     */
42
+    public function compile($extra = null) {}
43
+
44
+    /**
45
+     * Compiles a group of routes.
46
+     *
47
+     * @param      $hash
48
+     * @param null $extra
49
+     *
50
+     * @return mixed
51
+     */
52
+    public function compileGroup($compiledRoutes)
53
+    {
54
+
55
+        $this->replaceRoutes($compiledRoutes)
56
+            ->replaceRoutePrefix()
57
+            ->store(new FileToCompile(null, null));
58
+
59
+        return $this->stub;
60
+    }
61
+
62
+
63
+    /**
64
+     * Get output filename
65
+     *
66
+     *
67
+     * @return $this
68
+     */
69
+    protected function getOutputFilename()
70
+    {
71
+        $folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes);
72
+
73
+        return $folder  . 'routes.php';
74
+    }
75
+
76
+
77
+    /**
78
+     * Replace the resource.
79
+     *
80
+     * @param $this->modelName
81
+     *
82
+     * @return string routeStub
83
+     */
84
+    public function replaceResource($modelData)
85
+    {
86 86
 		
87
-		$routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource);
88
-		$routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub);
89
-		$routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub);
90
-		$routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub);
91
-
92
-		return $routeStub;
93
-	}
94
-
95
-	/**
96
-	 * Replace the reverse relationships.
97
-	 *
98
-	 * @param $this->modelData
99
-	 *
100
-	 * @return string functions
101
-	 */
102
-	public function replaceReverseRelationships($modelData)
103
-	{
104
-		$functions = '';
105
-
106
-		foreach ($modelData->reverseRelationships as $relationship)
107
-		{
108
-			if ($relationship)
109
-			{
110
-				$functionName = '';
111
-				if ($relationship->type == "hasOne")
112
-					$functionName = strtolower($relationship->modelName);
113
-				elseif ($relationship->type == "belongsToMany") 
114
-					$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
-				else 
116
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
117
-
118
-				$method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n";
119
-				$method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
120
-				$method = str_replace('{{function_name}}', $functionName, $method);
121
-				$method = str_replace('{{resource}}', $modelData->modelName, $method);
122
-
123
-				$functions .= $method;
124
-			}
125
-		}
126
-
127
-		return $functions;
128
-	}
129
-
130
-	/**
131
-	 * Replace the enum.
132
-	 *
133
-	 * @param $this->modelData
134
-	 *
135
-	 * @return string functions
136
-	 */
137
-	public function replaceEnum($modelData)
138
-	{
139
-		$functions = '';
140
-
141
-		foreach ($modelData->fields as $field)
142
-		{
143
-			if ($field->type->db == "enum")
144
-			{
145
-				$method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n";
146
-				$method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
147
-				$method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);
148
-				$method = str_replace('{{field_name}}', $field->name, $method);
149
-				$method = str_replace('{{resource}}', $modelData->modelName, $method);
150
-
151
-				$functions .= $method;
152
-			}
153
-		}
154
-
155
-		return $functions;
156
-	}
157
-
158
-
159
-	/**
160
-	 * Replace compiled routes.
161
-	 *
162
-	 * @param $compiledRoutes
163
-	 *
164
-	 * @return $this
165
-	 */
166
-	private function replaceRoutes($compiledRoutes)
167
-	{
168
-		$this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub);
169
-
170
-		return $this;
171
-	}
87
+        $routeStub = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $this->stubResource);
88
+        $routeStub = str_replace('{{resource}}', $modelData->modelName, $routeStub);
89
+        $routeStub = str_replace('{{reverseRelationships}}', $this->replaceReverseRelationships($modelData), $routeStub);
90
+        $routeStub = str_replace('{{enum}}', $this->replaceEnum($modelData), $routeStub);
91
+
92
+        return $routeStub;
93
+    }
94
+
95
+    /**
96
+     * Replace the reverse relationships.
97
+     *
98
+     * @param $this->modelData
99
+     *
100
+     * @return string functions
101
+     */
102
+    public function replaceReverseRelationships($modelData)
103
+    {
104
+        $functions = '';
105
+
106
+        foreach ($modelData->reverseRelationships as $relationship)
107
+        {
108
+            if ($relationship)
109
+            {
110
+                $functionName = '';
111
+                if ($relationship->type == "hasOne")
112
+                    $functionName = strtolower($relationship->modelName);
113
+                elseif ($relationship->type == "belongsToMany") 
114
+                    $functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
+                else 
116
+                    $functionName = CamelCase::pluralize(strtolower($relationship->modelName));
117
+
118
+                $method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n";
119
+                $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
120
+                $method = str_replace('{{function_name}}', $functionName, $method);
121
+                $method = str_replace('{{resource}}', $modelData->modelName, $method);
122
+
123
+                $functions .= $method;
124
+            }
125
+        }
126
+
127
+        return $functions;
128
+    }
129
+
130
+    /**
131
+     * Replace the enum.
132
+     *
133
+     * @param $this->modelData
134
+     *
135
+     * @return string functions
136
+     */
137
+    public function replaceEnum($modelData)
138
+    {
139
+        $functions = '';
140
+
141
+        foreach ($modelData->fields as $field)
142
+        {
143
+            if ($field->type->db == "enum")
144
+            {
145
+                $method = "\tRoute::get('{{resource_lw}}/{{field_name}}', '{{resource}}Controller@get{{field_name_uc}}Options');\n";
146
+                $method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
147
+                $method = str_replace('{{field_name_uc}}', CamelCase::convertToCamelCase($field->name), $method);
148
+                $method = str_replace('{{field_name}}', $field->name, $method);
149
+                $method = str_replace('{{resource}}', $modelData->modelName, $method);
150
+
151
+                $functions .= $method;
152
+            }
153
+        }
154
+
155
+        return $functions;
156
+    }
157
+
158
+
159
+    /**
160
+     * Replace compiled routes.
161
+     *
162
+     * @param $compiledRoutes
163
+     *
164
+     * @return $this
165
+     */
166
+    private function replaceRoutes($compiledRoutes)
167
+    {
168
+        $this->stub = str_replace('{{routes}}', $compiledRoutes, $this->stub);
169
+
170
+        return $this;
171
+    }
172 172
 
173 173
 	
174 174
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,18 +10,18 @@  discard block
 block discarded – undo
10 10
 
11 11
 class RouteCompiler extends AbstractCompiler
12 12
 {
13
-	protected $stubFilename = 'Routes.php' ;
13
+	protected $stubFilename = 'Routes.php';
14 14
 
15
-	protected $stubResourceFilename = 'ResourceRoute.php' ;
16
-	protected $stubResource  ;
15
+	protected $stubResourceFilename = 'ResourceRoute.php';
16
+	protected $stubResource;
17 17
 
18 18
 
19 19
 	public function __construct($scaffolderConfig, $modelData = null)
20 20
 	{
21
-		$this->stubsDirectory = __DIR__ . '/../../../../stubs/Api/';
21
+		$this->stubsDirectory = __DIR__.'/../../../../stubs/Api/';
22 22
 		parent::__construct($scaffolderConfig, null);
23 23
 		
24
-		$this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename );
24
+		$this->stubResource = File::get($this->stubsDirectory.$this->stubResourceFilename);
25 25
 	}
26 26
 
27 27
 	/**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @return string
31 31
 	 */
32
-	public function replaceAndStore(){}
32
+	public function replaceAndStore() {}
33 33
 
34 34
 	/**
35 35
 	 * Compiles a resource.
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	{
71 71
 		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->routes);
72 72
 
73
-		return $folder  . 'routes.php';
73
+		return $folder.'routes.php';
74 74
 	}
75 75
 
76 76
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -108,12 +108,13 @@
 block discarded – undo
108 108
 			if ($relationship)
109 109
 			{
110 110
 				$functionName = '';
111
-				if ($relationship->type == "hasOne")
112
-					$functionName = strtolower($relationship->modelName);
113
-				elseif ($relationship->type == "belongsToMany") 
114
-					$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
-				else 
116
-					$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
111
+				if ($relationship->type == "hasOne") {
112
+									$functionName = strtolower($relationship->modelName);
113
+				} elseif ($relationship->type == "belongsToMany") {
114
+									$functionName = CamelCase::pluralize(strtolower($relationship->relatedTable));
115
+				} else {
116
+									$functionName = CamelCase::pluralize(strtolower($relationship->modelName));
117
+				}
117 118
 
118 119
 				$method = "\tRoute::get('{{resource_lw}}/{id}/{{function_name}}', '{{resource}}Controller@{{function_name}}');\n";
119 120
 				$method = str_replace('{{resource_lw}}', strtolower($modelData->modelName), $method);
Please login to merge, or discard this patch.