Completed
Push — master ( c7b947...966759 )
by Thomas
08:09
created

GeneratorFactory   C

Complexity

Total Complexity 27

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 21

Test Coverage

Coverage 84.62%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 27
c 8
b 0
f 0
lcom 1
cbo 21
dl 0
loc 120
rs 6.1111
ccs 11
cts 13
cp 0.8462

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
C createActionRelationshipGenerator() 0 25 8
B createModelActionGenerator() 0 18 6
B createModelJsonResponderGenerator() 0 18 6
A createPackageGenerator() 0 9 3
A createPayloadGenerator() 0 9 3
1
<?php
2
namespace keeko\tools\generator;
3
4
use keeko\tools\generator\action\AbstractModelActionGenerator;
5
use keeko\tools\generator\action\ModelCreateActionGenerator;
6
use keeko\tools\generator\action\ModelDeleteActionGenerator;
7
use keeko\tools\generator\action\ModelListActionGenerator;
8
use keeko\tools\generator\action\ModelReadActionGenerator;
9
use keeko\tools\generator\action\ModelUpdateActionGenerator;
10
use keeko\tools\generator\package\AbstractPackageGenerator;
11
use keeko\tools\generator\package\AppPackageGenerator;
12
use keeko\tools\generator\package\ModulePackageGenerator;
13
use keeko\tools\generator\responder\AbstractModelJsonResponderGenerator;
14 5
use keeko\tools\generator\responder\ModelCreateJsonResponderGenerator;
15
use keeko\tools\generator\responder\ModelDeleteJsonResponderGenerator;
16 5
use keeko\tools\generator\responder\ModelListJsonResponderGenerator;
17 4
use keeko\tools\generator\responder\ModelReadJsonResponderGenerator;
18
use keeko\tools\generator\responder\ModelUpdateJsonResponderGenerator;
19 5
use keeko\tools\generator\responder\PayloadHtmlResponderGenerator;
20 5
use keeko\tools\generator\responder\PayloadJsonResponderGenerator;
21
use keeko\tools\services\CommandService;
22 3
use keeko\tools\model\Relationship;
23 3
use keeko\tools\generator\action\AbstractActionGenerator;
24
use keeko\tools\generator\action\ToOneRelationshipReadActionGenerator;
25 3
use keeko\tools\generator\action\ToOneRelationshipUpdateActionGenerator;
26 3
use keeko\tools\generator\action\ToManyRelationshipReadActionGenerator;
27
use keeko\tools\generator\action\ToManyRelationshipUpdateActionGenerator;
28 3
use keeko\tools\generator\action\ToManyRelationshipAddActionGenerator;
29 3
use keeko\tools\generator\action\ToManyRelationshipRemoveActionGenerator;
30
31
class GeneratorFactory {
32
	
33
	private $service;
34
	
35
	public function __construct(CommandService $service) {
36
		$this->service = $service;
37
	}
38
	
39 2
	/**
40
	 * Creates a generator for a relationship action
41 2
	 * 
42 1
	 * @param string $type
43
	 * @param Relationship $relationship
44 2
	 * @return AbstractActionGenerator
45 2
	 */
46
	public function createActionRelationshipGenerator($type, Relationship $relationship) {
47 1
		if ($relationship->getType() == Relationship::ONE_TO_ONE) {
48 1
			switch ($type) {
49
				case 'read':
50 1
					return new ToOneRelationshipReadActionGenerator($this->service);
51 1
					
52
				case 'update':
53 1
					return new ToOneRelationshipUpdateActionGenerator($this->service);
54 1
			}
55
		} else {
56
			switch ($type) {
57
				case 'read':
58
					return new ToManyRelationshipReadActionGenerator($this->service);
59
					
60
				case 'update':
61
					return new ToManyRelationshipUpdateActionGenerator($this->service);
62
					
63
				case 'add':
64
					return new ToManyRelationshipAddActionGenerator($this->service);
65
					
66
				case 'remove':
67
					return new ToManyRelationshipRemoveActionGenerator($this->service);
68
			}
69
		}
70
	}
71
	
72
	/**
73
	 * Creates a generator for the given trait type
74
	 * 
75
	 * @param string $type
76
	 * @return AbstractModelActionGenerator
77
	 */
78
	public function createModelActionGenerator($type) {
79
		switch ($type) {
80
			case 'list':
81
				return new ModelListActionGenerator($this->service);
82
				
83
			case 'create':
84
				return new ModelCreateActionGenerator($this->service);
85
				
86
			case 'update':
87
				return new ModelUpdateActionGenerator($this->service);
88
				
89
			case 'read':
90
				return new ModelReadActionGenerator($this->service);
91
				
92
			case 'delete':
93
				return new ModelDeleteActionGenerator($this->service);
94
		}
95
	}
96
	
97
	/**
98
	 * Creates a generator for the given json respose
99
	 * 
100
	 * @param string $type
101
	 * @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...
102
	 * @return AbstractModelJsonResponderGenerator
103
	 */
104
	public function createModelJsonResponderGenerator($type) {
105
		switch ($type) {
106
			case 'list':
107
				return new ModelListJsonResponderGenerator($this->service);
108
109
			case 'create':
110
				return new ModelCreateJsonResponderGenerator($this->service);
111
		
112
			case 'update':
113
				return new ModelUpdateJsonResponderGenerator($this->service);
114
		
115
			case 'read':
116
				return new ModelReadJsonResponderGenerator($this->service);
117
		
118
			case 'delete':
119
				return new ModelDeleteJsonResponderGenerator($this->service);
120
		}
121
	}
122
123
	/**
124
	 * Creates a new package generator
125
	 * 
126
	 * @param string $type
127
	 * @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...
128
	 * @return AbstractPackageGenerator
129
	 */
130
	public function createPackageGenerator($type) {
131
		switch ($type) {
132
			case 'app':
133
				return new AppPackageGenerator($this->service);
134
				
135
			case 'module':
136
				return new ModulePackageGenerator($this->service);
137
		}
138
	}
139
	
140
	public function createPayloadGenerator($format) {
141
		switch ($format) {
142
			case 'json':
143
				return new PayloadJsonResponderGenerator($this->service);
144
				
145
			case 'html':
146
				return new PayloadHtmlResponderGenerator($this->service);
147
		}
148
	}
149
	
150
}
151