Conditions | 11 |
Paths | 148 |
Total Lines | 55 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
113 | public function isStructureOK(&$msg = null) |
||
114 | { |
||
115 | $entityTypeNames = []; |
||
116 | $associationNames = []; |
||
117 | $this->getEntityType(); |
||
118 | foreach ($this->getEntityType() as $entityType) { |
||
119 | $entityTypeNames[] = $entityType->getName(); |
||
120 | } |
||
121 | foreach ($this->association as $association) { |
||
122 | $associationNames[] = $association->getName(); |
||
123 | } |
||
124 | |||
125 | $entitySets = $this->getEntityContainer()[0]->getEntitySet(); |
||
126 | foreach ($entitySets as $eset) { |
||
127 | $eSetType = $eset->getEntityType(); |
||
128 | /*if (substr($eSetType, 0, strlen($this->getNamespace())) != $this->getNamespace()) { |
||
129 | $msg = "Types for Entity Sets should have the namespace at the beginning " . __CLASS__; |
||
130 | die($this->getNamespace()); |
||
131 | return false; |
||
132 | }*/ |
||
133 | $eSetType = str_replace($this->getNamespace() . ".", "", $eSetType); |
||
134 | if (!in_array($eSetType, $entityTypeNames)) { |
||
135 | $msg = "entitySet Types should have a matching type name in entity Types"; |
||
136 | return false; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | // Check Associations to assocationSets |
||
141 | $found = false; |
||
142 | $namespaceLen = strlen($this->namespace); |
||
143 | if (0 != $namespaceLen) { |
||
144 | $namespaceLen++; |
||
145 | } |
||
146 | foreach ($this->association as $assocation) { |
||
147 | foreach ($this->entityContainer->associationSet as $assocationSet) { |
||
148 | if ($assocation->getName() == substr($assocationSet->association, $namespaceLen)) { |
||
149 | $aEnd1 = $assocationSet->getEnd()[0]; |
||
150 | $aEnd2 = $assocationSet->getEnd()[1]; |
||
151 | $asEnd1 = $assocationSet->getEnd()[0]; |
||
152 | $asEnd2 = $assocationSet->getEnd()[1]; |
||
153 | //== TRUE if $a and $b have the same key/value pairs. |
||
154 | //===TRUE if $a and $b have the same key/value pairs in the same order and of the same types. |
||
155 | if ([$aEnd1->getRole(), $aEnd2->getRole()] == [$asEnd1->getRole(), $asEnd2->getRole()]) { |
||
156 | $found = true; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | if (!$found) { |
||
161 | $msg = "can not find assocationset with matching roles for assocation"; |
||
162 | return false; |
||
163 | } |
||
164 | $found = false; |
||
165 | } |
||
166 | return true; |
||
167 | } |
||
168 | |||
195 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.