| Conditions | 14 |
| Paths | 272 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 91 | public static function fromModel(ContextModel $model) |
||
| 92 | { |
||
| 93 | $context = new self(); |
||
| 94 | $context->registration = $model->getRegistration(); |
||
| 95 | $context->revision = $model->getRevision(); |
||
| 96 | $context->platform = $model->getPlatform(); |
||
| 97 | $context->language = $model->getLanguage(); |
||
| 98 | |||
| 99 | if (null !== $instructor = $model->getInstructor()) { |
||
| 100 | $context->instructor = StatementObject::fromModel($instructor); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (null !== $team = $model->getTeam()) { |
||
| 104 | $context->team = StatementObject::fromModel($team); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (null !== $contextActivities = $model->getContextActivities()) { |
||
| 108 | $context->hasContextActivities = true; |
||
| 109 | |||
| 110 | if (null !== $parentActivities = $contextActivities->getParentActivities()) { |
||
| 111 | $context->parentActivities = array(); |
||
| 112 | |||
| 113 | foreach ($parentActivities as $parentActivity) { |
||
| 114 | $activity = StatementObject::fromModel($parentActivity); |
||
| 115 | $activity->parentContext = $context; |
||
|
|
|||
| 116 | $context->parentActivities[] = $activity; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | if (null !== $groupingActivities = $contextActivities->getGroupingActivities()) { |
||
| 121 | $context->groupingActivities = array(); |
||
| 122 | |||
| 123 | foreach ($groupingActivities as $groupingActivity) { |
||
| 124 | $activity = StatementObject::fromModel($groupingActivity); |
||
| 125 | $activity->groupingContext = $context; |
||
| 126 | $context->groupingActivities[] = $activity; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | if (null !== $categoryActivities = $contextActivities->getCategoryActivities()) { |
||
| 131 | $context->categoryActivities = array(); |
||
| 132 | |||
| 133 | foreach ($categoryActivities as $categoryActivity) { |
||
| 134 | $activity = StatementObject::fromModel($categoryActivity); |
||
| 135 | $activity->categoryContext = $context; |
||
| 136 | $context->categoryActivities[] = $activity; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | if (null !== $otherActivities = $contextActivities->getOtherActivities()) { |
||
| 141 | $context->otherActivities = array(); |
||
| 142 | |||
| 143 | foreach ($otherActivities as $otherActivity) { |
||
| 144 | $activity = StatementObject::fromModel($otherActivity); |
||
| 145 | $activity->otherContext = $context; |
||
| 146 | $context->otherActivities[] = $activity; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | $context->hasContextActivities = false; |
||
| 151 | } |
||
| 152 | |||
| 153 | if (null !== $statementReference = $model->getStatement()) { |
||
| 154 | $context->statement = $statementReference->getStatementId()->getValue(); |
||
| 155 | } |
||
| 156 | |||
| 157 | if (null !== $contextExtensions = $model->getExtensions()) { |
||
| 158 | $context->extensions = Extensions::fromModel($contextExtensions); |
||
| 159 | } |
||
| 160 | |||
| 161 | return $context; |
||
| 162 | } |
||
| 163 | |||
| 221 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..