Completed
Push — master ( 43a701...9aa864 )
by Thomas
13:49
created

getRelationshipMethodNameGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
ccs 0
cts 0
cp 0
cc 2
eloc 4
nc 2
nop 0
crap 6
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
use keeko\tools\generator\name\RelationshipMethodNameGenerator;
39 2
40
class GeneratorFactory {
41 2
42 1
	/** @var CommandService */
43
	private $service;
44 2
45 2
	/** @var ActionNameGenerator */
46
	private $actionNameGenerator;
47 1
48 1
	/** @var ActionClassNameGenerator */
49
	private $actionClassNameGenerator;
50 1
51 1
	/** @var ActionTitleGenerator */
52
	private $actionTitleGenerator;
53 1
54 1
	/** @var NamespaceGenerator */
55
	private $namespaceGenerator;
56
57
	/** @var ResponderClassNameGenerator */
58
	private $responderClassNameGenerator;
59
60
	/** @var RelationshipMethodNameGenerator */
61
	private $relationshipMethodNameGenerator;
62
63
	public function __construct(CommandService $service) {
64
		$this->service = $service;
65
	}
66
67
	/**
68
	 * Creates a new package generator
69
	 *
70
	 * @param string $type
71
	 * @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...
72
	 * @return AbstractPackageGenerator
73
	 */
74
	public function createPackageGenerator($type) {
75
		switch ($type) {
76
			case 'app':
77
				return new AppPackageGenerator($this->service);
78
79
			case 'module':
80
				return new ModulePackageGenerator($this->service);
81
		}
82
	}
83
84
	/**
85
	 * Creates a generator for the given trait type
86
	 *
87
	 * @param string $type
88
	 * @return AbstractModelActionGenerator
89
	 */
90
	public function createModelActionGenerator($type) {
91
		switch ($type) {
92
			case Types::PAGINATE:
93
				return new ModelPaginateActionGenerator($this->service);
94
95
			case Types::CREATE:
96
				return new ModelCreateActionGenerator($this->service);
97
98
			case Types::UPDATE:
99
				return new ModelUpdateActionGenerator($this->service);
100
101
			case Types::READ:
102
				return new ModelReadActionGenerator($this->service);
103
104
			case Types::DELETE:
105
				return new ModelDeleteActionGenerator($this->service);
106
		}
107
	}
108
109
	/**
110
	 * Creates a generator for a relationship action
111
	 *
112
	 * @param string $type
113
	 * @param Relationship $relationship
114
	 * @return AbstractActionGenerator
115
	 */
116
	public function createRelationshipActionGenerator($type, Relationship $relationship) {
117
		if ($relationship->getType() == Relationship::ONE_TO_ONE) {
118
			switch ($type) {
119
				case Types::READ:
120
					return new ToOneRelationshipReadActionGenerator($this->service);
121
122
				case Types::UPDATE:
123
					return new ToOneRelationshipUpdateActionGenerator($this->service);
124
			}
125
		} else {
126
			switch ($type) {
127
				case Types::READ:
128
					return new ToManyRelationshipReadActionGenerator($this->service);
129
130
				case Types::UPDATE:
131
					return new ToManyRelationshipUpdateActionGenerator($this->service);
132
133
				case Types::ADD:
134
					return new ToManyRelationshipAddActionGenerator($this->service);
135
136
				case Types::REMOVE:
137
					return new ToManyRelationshipRemoveActionGenerator($this->service);
138
			}
139
		}
140
	}
141
142
	/**
143
	 * Creates a generator for the given json respose
144
	 *
145
	 * @param string $type
146
	 * @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...
147
	 * @return AbstractModelJsonResponderGenerator
148
	 */
149
	public function createModelJsonResponderGenerator($type) {
150
		switch ($type) {
151
			case Types::PAGINATE:
152
				return new ModelPaginateJsonResponderGenerator($this->service);
153
154
			case Types::CREATE:
155
				return new ModelCreateJsonResponderGenerator($this->service);
156
157
			case Types::UPDATE:
158
				return new ModelUpdateJsonResponderGenerator($this->service);
159
160
			case Types::READ:
161
				return new ModelReadJsonResponderGenerator($this->service);
162
163
			case Types::DELETE:
164
				return new ModelDeleteJsonResponderGenerator($this->service);
165
		}
166
	}
167
168
	/**
169
	 * Creates a json generator for a relationship
170
	 *
171
	 * @param Relationship $relationship
172
	 * @return AbstractModelJsonResponderGenerator
173
	 */
174
	public function createRelationshipJsonResponderGenerator(Relationship $relationship) {
175
		return $relationship->getType() == Relationship::ONE_TO_ONE
176
			? new ToOneRelationshipJsonResponderGenerator($this->service, $relationship)
177
			: new ToManyRelationshipJsonResponderGenerator($this->service, $relationship);
178
	}
179
180
	/**
181
	 * Creates a payload responder for the given format
182
	 *
183
	 * @param string $format
184
	 * @return AbstractResponderGenerator
185
	 */
186
	public function createPayloadResponderGenerator($format) {
187
		switch ($format) {
188
			case 'json':
189
				return new PayloadJsonResponderGenerator($this->service);
190
191
			case 'html':
192
				return new PayloadHtmlResponderGenerator($this->service);
193
		}
194
	}
195
196
	/**
197
	 * @return ActionNameGenerator
198
	 */
199
	public function getActionNameGenerator() {
200
		if ($this->actionNameGenerator === null) {
201
			$this->actionNameGenerator = new ActionNameGenerator($this->service);
202
		}
203
204
		return $this->actionNameGenerator;
205
	}
206
207
	/**
208
	 * @return ActionClassNameGenerator
209
	 */
210
	public function getActionClassNameGenerator() {
211
		if ($this->actionClassNameGenerator === null) {
212
			$this->actionClassNameGenerator = new ActionClassNameGenerator($this->service);
213
		}
214
215
		return $this->actionClassNameGenerator;
216
	}
217
218
	/**
219
	 * @return ActionTitleGenerator
220
	 */
221
	public function getActionTitleGenerator() {
222
		if ($this->actionTitleGenerator === null) {
223
			$this->actionTitleGenerator = new ActionTitleGenerator($this->service);
224
		}
225
226
		return $this->actionTitleGenerator;
227
	}
228
229
	/**
230
	 * @return NamespaceGenerator
231
	 */
232
	public function getNamespaceGenerator() {
233
		if ($this->namespaceGenerator === null) {
234
			$this->namespaceGenerator = new NamespaceGenerator($this->service);
235
		}
236
237
		return $this->namespaceGenerator;
238
	}
239
240
	/**
241
	 * @return ResponderClassNameGenerator
242
	 */
243
	public function getResponderClassNameGenerator() {
244
		if ($this->responderClassNameGenerator === null) {
245
			$this->responderClassNameGenerator = new ResponderClassNameGenerator($this->service);
246
		}
247
248
		return $this->responderClassNameGenerator;
249
	}
250
251
	/**
252
	 * @return RelationshipMethodNameGenerator
253
	 */
254
	public function getRelationshipMethodNameGenerator() {
255
		if ($this->relationshipMethodNameGenerator === null) {
256
			$this->relationshipMethodNameGenerator = new RelationshipMethodNameGenerator($this->service);
257
		}
258
259
		return $this->relationshipMethodNameGenerator;
260
	}
261
}
262