Conditions | 18 |
Paths | 1752 |
Total Lines | 88 |
Code Lines | 57 |
Lines | 20 |
Ratio | 22.73 % |
Changes | 6 | ||
Bugs | 0 | Features | 1 |
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 |
||
116 | public function isStructureOK(&$msg = null) |
||
117 | { |
||
118 | $entityTypeNames = []; |
||
119 | $associationNames = []; |
||
120 | $navigationProperties = []; |
||
121 | $associationSets = []; |
||
122 | $namespaceLen = strlen($this->namespace); |
||
123 | if (0 != $namespaceLen) { |
||
124 | $namespaceLen++; |
||
125 | } |
||
126 | |||
127 | foreach ($this->getEntityType() as $entityType) { |
||
128 | $entityTypeNames[] = $entityType->getName(); |
||
129 | foreach ($entityType->getNavigationProperty() as $navigationProperty) { |
||
130 | $navigationProperties[ |
||
131 | substr($navigationProperty->getRelationship(), $namespaceLen) |
||
132 | ][] = $navigationProperty; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | foreach ($this->association as $association) { |
||
137 | $associationNames[$association->getName()] = $association->getEnd(); |
||
138 | } |
||
139 | foreach ($this->getEntityContainer()[0]->getAssociationSet() as $associationSet) { |
||
140 | $associationSets[substr($associationSet->getAssociation(), $namespaceLen)] = $associationSet->getEnd(); |
||
141 | } |
||
142 | |||
143 | |||
144 | $entitySets = $this->getEntityContainer()[0]->getEntitySet(); |
||
145 | foreach ($entitySets as $eset) { |
||
146 | $eSetType = $eset->getEntityType(); |
||
147 | /*if (substr($eSetType, 0, strlen($this->getNamespace())) != $this->getNamespace()) { |
||
148 | $msg = "Types for Entity Sets should have the namespace at the beginning " . __CLASS__; |
||
149 | die($this->getNamespace()); |
||
150 | return false; |
||
151 | }*/ |
||
152 | $eSetType = str_replace($this->getNamespace() . ".", "", $eSetType); |
||
153 | if (!in_array($eSetType, $entityTypeNames)) { |
||
154 | $msg = "entitySet Types should have a matching type name in entity Types"; |
||
155 | return false; |
||
156 | } |
||
157 | } |
||
158 | |||
159 | // Check Associations to associationSets |
||
160 | if (count($associationSets) != count($associationNames)) { |
||
161 | $msg = "we have " . count($associationSets) . "association sets and " . count($associationNames) |
||
162 | . " associations, they should be the same"; |
||
163 | } |
||
164 | if (count($associationNames) * 2 < count($navigationProperties)) { |
||
165 | $msg = "we have too many navigation properties. should have no more then double the" |
||
166 | ." number of associations."; |
||
167 | } |
||
168 | foreach ($associationNames as $associationName => $associationEnds) { |
||
169 | if (!array_key_exists($associationName, $associationSets)) { |
||
170 | $msg = "association " . $associationName . " exists without matching associationSet"; |
||
171 | return false; |
||
172 | } |
||
173 | |||
174 | if (!array_key_exists($associationName, $navigationProperties)) { |
||
175 | $msg = "association " . $associationName . " exists without matching Natvigation Property"; |
||
176 | return false; |
||
177 | } |
||
178 | $roles = [$associationEnds[0]->getRole(), $associationEnds[1]->getRole()]; |
||
179 | View Code Duplication | if (!in_array($associationSets[$associationName][0]->getRole(), $roles)) { |
|
180 | $msg = "association Set role " . $associationSets[$associationName][0]->getRole() |
||
181 | . "lacks a matching property in the attached association"; |
||
182 | return false; |
||
183 | } |
||
184 | View Code Duplication | if (!in_array($associationSets[$associationName][1]->getRole(), $roles)) { |
|
185 | $msg = "association Set role " . $associationSets[$associationName][1]->getRole() |
||
186 | . "lacks a matching property in the attached association"; |
||
187 | return false; |
||
188 | } |
||
189 | foreach($navigationProperties[$associationName] as $navProp){ |
||
190 | View Code Duplication | if (!in_array($navProp->getToRole(),$roles)) { |
|
191 | $msg = "Navigation Property Role " . $navProp->getToRole() |
||
192 | . " lacks a matching peroperty in the assocation"; |
||
193 | return false; |
||
194 | } |
||
195 | View Code Duplication | if (!in_array($navProp->getFromRole(),$roles)) { |
|
196 | $msg = "Navigation Property Role " .$navProp->getToRole() |
||
197 | . " lacks a matching peroperty in the assocation"; |
||
198 | return false; |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | return true; |
||
203 | } |
||
204 | |||
236 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.