Completed
Push — master ( d6c5c0...118f52 )
by Thomas
04:57
created

GeneratorFactory   D

Complexity

Total Complexity 39

Size/Duplication

Total Lines 208
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 28

Test Coverage

Coverage 91.67%

Importance

Changes 9
Bugs 0 Features 0
Metric Value
wmc 39
c 9
b 0
f 0
lcom 1
cbo 28
dl 0
loc 208
ccs 11
cts 12
cp 0.9167
rs 4.2439

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createPackageGenerator() 0 9 3
B createModelActionGenerator() 0 18 6
C createRelationshipActionGenerator() 0 25 8
B createModelJsonResponderGenerator() 0 18 6
A createRelationshipJsonResponderGenerator() 0 5 2
A createPayloadResponderGenerator() 0 9 3
A getActionNameGenerator() 0 7 2
A getActionClassNameGenerator() 0 7 2
A getActionTitleGenerator() 0 7 2
A getNamespaceGenerator() 0 7 2
A getResponderClassNameGenerator() 0 7 2
1
<?php
2
namespace keeko\tools\generator;
3
4
use keeko\tools\generator\action\AbstractActionGenerator;
5
use keeko\tools\generator\action\AbstractModelActionGenerator;
6
use keeko\tools\generator\action\ModelCreateActionGenerator;
7
use keeko\tools\generator\action\ModelDeleteActionGenerator;
8
use keeko\tools\generator\action\ModelPaginateActionGenerator;
9
use keeko\tools\generator\action\ModelReadActionGenerator;
10
use keeko\tools\generator\action\ModelUpdateActionGenerator;
11
use keeko\tools\generator\action\ToManyRelationshipAddActionGenerator;
12
use keeko\tools\generator\action\ToManyRelationshipReadActionGenerator;
13
use keeko\tools\generator\action\ToManyRelationshipRemoveActionGenerator;
14 5
use keeko\tools\generator\action\ToManyRelationshipUpdateActionGenerator;
15
use keeko\tools\generator\action\ToOneRelationshipReadActionGenerator;
16 5
use keeko\tools\generator\action\ToOneRelationshipUpdateActionGenerator;
17 4
use keeko\tools\generator\name\ActionClassNameGenerator;
18
use keeko\tools\generator\name\ActionNameGenerator;
19 5
use keeko\tools\generator\name\ActionTitleGenerator;
20 5
use keeko\tools\generator\name\NamespaceGenerator;
21
use keeko\tools\generator\name\ResponderClassNameGenerator;
22 3
use keeko\tools\generator\package\AbstractPackageGenerator;
23 3
use keeko\tools\generator\package\AppPackageGenerator;
24
use keeko\tools\generator\package\ModulePackageGenerator;
25 3
use keeko\tools\generator\responder\AbstractModelJsonResponderGenerator;
26 3
use keeko\tools\generator\responder\AbstractResponderGenerator;
27
use keeko\tools\generator\responder\ModelCreateJsonResponderGenerator;
28 3
use keeko\tools\generator\responder\ModelDeleteJsonResponderGenerator;
29 3
use keeko\tools\generator\responder\ModelPaginateJsonResponderGenerator;
30
use keeko\tools\generator\responder\ModelReadJsonResponderGenerator;
31
use keeko\tools\generator\responder\ModelUpdateJsonResponderGenerator;
32
use keeko\tools\generator\responder\PayloadHtmlResponderGenerator;
33
use keeko\tools\generator\responder\PayloadJsonResponderGenerator;
34
use keeko\tools\generator\responder\ToManyRelationshipJsonResponderGenerator;
35
use keeko\tools\generator\responder\ToOneRelationshipJsonResponderGenerator;
36
use keeko\tools\model\Relationship;
37
use keeko\tools\services\CommandService;
38
39 2
class GeneratorFactory {
40
	
41 2
	/** @var CommandService */
42 1
	private $service;
43
	
44 2
	/** @var ActionNameGenerator */
45 2
	private $actionNameGenerator;
46
	
47 1
	/** @var ActionClassNameGenerator */
48 1
	private $actionClassNameGenerator;
49
	
50 1
	/** @var ActionTitleGenerator */
51 1
	private $actionTitleGenerator;
52
	
53 1
	/** @var NamespaceGenerator */
54 1
	private $namespaceGenerator;
55
	
56
	/** @var ResponderClassNameGenerator */
57
	private $responderClassNameGenerator;
58
	
59
	public function __construct(CommandService $service) {
60
		$this->service = $service;
61
	}
62
	
63
	/**
64
	 * Creates a new package generator
65
	 *
66
	 * @param string $type
67
	 * @param CommandService $this->serivce
0 ignored issues
show
Bug introduced by
There is no parameter named $this->serivce. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
68
	 * @return AbstractPackageGenerator
69
	 */
70
	public function createPackageGenerator($type) {
71
		switch ($type) {
72
			case 'app':
73
				return new AppPackageGenerator($this->service);
74
	
75
			case 'module':
76
				return new ModulePackageGenerator($this->service);
77
		}
78
	}
79
	
80
	/**
81
	 * Creates a generator for the given trait type
82
	 *
83
	 * @param string $type
84
	 * @return AbstractModelActionGenerator
85
	 */
86
	public function createModelActionGenerator($type) {
87
		switch ($type) {
88
			case Types::PAGINATE:
89
				return new ModelPaginateActionGenerator($this->service);
90
	
91
			case Types::CREATE:
92
				return new ModelCreateActionGenerator($this->service);
93
	
94
			case Types::UPDATE:
95
				return new ModelUpdateActionGenerator($this->service);
96
	
97
			case Types::READ:
98
				return new ModelReadActionGenerator($this->service);
99
	
100
			case Types::DELETE:
101
				return new ModelDeleteActionGenerator($this->service);
102
		}
103
	}
104
	
105
	/**
106
	 * Creates a generator for a relationship action
107
	 * 
108
	 * @param string $type
109
	 * @param Relationship $relationship
110
	 * @return AbstractActionGenerator
111
	 */
112
	public function createRelationshipActionGenerator($type, Relationship $relationship) {
113
		if ($relationship->getType() == Relationship::ONE_TO_ONE) {
114
			switch ($type) {
115
				case Types::READ:
116
					return new ToOneRelationshipReadActionGenerator($this->service);
117
					
118
				case Types::UPDATE:
119
					return new ToOneRelationshipUpdateActionGenerator($this->service);
120
			}
121
		} else {
122
			switch ($type) {
123
				case Types::READ:
124
					return new ToManyRelationshipReadActionGenerator($this->service);
125
					
126
				case Types::UPDATE:
127
					return new ToManyRelationshipUpdateActionGenerator($this->service);
128
					
129
				case Types::ADD:
130
					return new ToManyRelationshipAddActionGenerator($this->service);
131
					
132
				case Types::REMOVE:
133
					return new ToManyRelationshipRemoveActionGenerator($this->service);
134
			}
135
		}
136
	}
137
	
138
	/**
139
	 * Creates a generator for the given json respose
140
	 * 
141
	 * @param string $type
142
	 * @param CommandService $this->service
0 ignored issues
show
Bug introduced by
There is no parameter named $this->service. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
143
	 * @return AbstractModelJsonResponderGenerator
144
	 */
145
	public function createModelJsonResponderGenerator($type) {
146
		switch ($type) {
147
			case Types::PAGINATE:
148
				return new ModelPaginateJsonResponderGenerator($this->service);
149
150
			case Types::CREATE:
151
				return new ModelCreateJsonResponderGenerator($this->service);
152
		
153
			case Types::UPDATE:
154
				return new ModelUpdateJsonResponderGenerator($this->service);
155
		
156
			case Types::READ:
157
				return new ModelReadJsonResponderGenerator($this->service);
158
		
159
			case Types::DELETE:
160
				return new ModelDeleteJsonResponderGenerator($this->service);
161
		}
162
	}
163
	
164
	/**
165
	 * Creates a json generator for a relationship
166
	 * 
167
	 * @param Relationship $relationship
168
	 * @return AbstractModelJsonResponderGenerator
169
	 */
170
	public function createRelationshipJsonResponderGenerator(Relationship $relationship) {
171
		return $relationship->getType() == Relationship::ONE_TO_ONE
172
			? new ToOneRelationshipJsonResponderGenerator($this->service, $relationship)
173
			: new ToManyRelationshipJsonResponderGenerator($this->service, $relationship);
174
	}
175
	
176
	/**
177
	 * Creates a payload responder for the given format
178
	 *  
179
	 * @param string $format
180
	 * @return AbstractResponderGenerator
181
	 */
182
	public function createPayloadResponderGenerator($format) {
183
		switch ($format) {
184
			case 'json':
185
				return new PayloadJsonResponderGenerator($this->service);
186
	
187
			case 'html':
188
				return new PayloadHtmlResponderGenerator($this->service);
189
		}
190
	}
191
	
192
	/**
193
	 * @return ActionNameGenerator
194
	 */
195
	public function getActionNameGenerator() {
196
		if ($this->actionNameGenerator === null) {
197
			$this->actionNameGenerator = new ActionNameGenerator($this->service);
198
		}
199
		
200
		return $this->actionNameGenerator;
201
	}
202
	
203
	/**
204
	 * @return ActionClassNameGenerator
205
	 */
206
	public function getActionClassNameGenerator() {
207
		if ($this->actionClassNameGenerator === null) {
208
			$this->actionClassNameGenerator = new ActionClassNameGenerator($this->service);
209
		}
210
	
211
		return $this->actionClassNameGenerator;
212
	}
213
	
214
	/**
215
	 * @return ActionTitleGenerator
216
	 */
217
	public function getActionTitleGenerator() {
218
		if ($this->actionTitleGenerator === null) {
219
			$this->actionTitleGenerator = new ActionTitleGenerator($this->service);
220
		}
221
	
222
		return $this->actionTitleGenerator;
223
	}
224
225
	/**
226
	 * @return NamespaceGenerator
227
	 */
228
	public function getNamespaceGenerator() {
229
		if ($this->namespaceGenerator === null) {
230
			$this->namespaceGenerator = new NamespaceGenerator($this->service);
231
		}
232
		
233
		return $this->namespaceGenerator;
234
	}
235
	
236
	/**
237
	 * @return ResponderClassNameGenerator
238
	 */
239
	public function getResponderClassNameGenerator() {
240
		if ($this->responderClassNameGenerator === null) {
241
			$this->responderClassNameGenerator = new ResponderClassNameGenerator($this->service);
242
		}
243
		
244
		return $this->responderClassNameGenerator;
245
	}
246
}
247