Conditions | 14 |
Paths | 46 |
Total Lines | 58 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
82 | public function getExampleValue($obj, $name, $type) |
||
83 | { |
||
84 | $value = null; |
||
85 | $ignoreList = $this->Config()->get('fields_to_ignore_for_updates'); |
||
86 | if (isset($this->listOfFieldTypesRaw[$type])) { |
||
87 | ++$this->listOfFieldTypesRaw[$type]; |
||
88 | } else { |
||
89 | $this->listOfFieldTypesRaw[$type] = 1; |
||
90 | } |
||
91 | if (in_array($name, $ignoreList, true)) { |
||
92 | $this->flushNow('... ... SKIPPING ' . $name); |
||
93 | } else { |
||
94 | $typeArray = explode('(', $type); |
||
95 | $realType = $typeArray[0]; |
||
96 | |||
97 | switch ($realType) { |
||
98 | case 'Varchar': |
||
99 | case 'Text': |
||
100 | $value = 'TestValue'; |
||
101 | |||
102 | break; |
||
103 | case 'Boolean': |
||
104 | $value = 1; |
||
105 | |||
106 | break; |
||
107 | case 'HTMLText': |
||
108 | case 'HTMLFragment': |
||
109 | $value = '<p>Hello World'; |
||
110 | |||
111 | break; |
||
112 | case 'Int': |
||
113 | $value = 2; |
||
114 | |||
115 | break; |
||
116 | case 'Enum': |
||
117 | $values = $obj->dbObject($name)->enumValues(false); |
||
118 | $value = key($values); |
||
119 | |||
120 | break; |
||
121 | case 'DBFile': |
||
122 | break; |
||
123 | case 'Datetime': |
||
124 | $value = date('Y-m-d h:i:s'); |
||
125 | |||
126 | break; |
||
127 | case 'Date': |
||
128 | $value = date('Y-m-d'); |
||
129 | |||
130 | break; |
||
131 | } |
||
132 | if (isset($this->listOfFieldTypesClean[$realType])) { |
||
133 | ++$this->listOfFieldTypesClean[$realType]; |
||
134 | } else { |
||
135 | $this->listOfFieldTypesClean[$realType] = 1; |
||
136 | } |
||
137 | } |
||
138 | |||
139 | return $value; |
||
140 | } |
||
192 |