| Conditions | 14 |
| Paths | 28 |
| Total Lines | 74 |
| Code Lines | 39 |
| 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 |
||
| 49 | public function tryGetRelativeEntitySetPath( |
||
| 50 | IModel $model, |
||
| 51 | IFunctionParameter &$parameter = null, |
||
| 52 | array &$path = null |
||
| 53 | ): bool { |
||
| 54 | /** |
||
| 55 | * @var IFunctionImport $this |
||
| 56 | */ |
||
| 57 | $parameter = null; |
||
| 58 | $path = null; |
||
| 59 | |||
| 60 | $entitySetPath = $this->getEntitySet(); |
||
| 61 | $entitySetPath = $entitySetPath instanceof IPathExpression ? $entitySetPath : null; |
||
| 62 | if ($entitySetPath === null) { |
||
| 63 | return false; |
||
| 64 | } |
||
| 65 | |||
| 66 | $pathToResolve = $entitySetPath->getPath(); |
||
| 67 | $numSegments = count($pathToResolve); |
||
| 68 | if (0 === $numSegments) { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Resolve the first segment as a parameter. |
||
| 73 | $parameter = $this->findParameter($pathToResolve[0]); |
||
| 74 | if ($parameter === null) { |
||
| 75 | return false; |
||
| 76 | } |
||
| 77 | |||
| 78 | if (1 === $numSegments) { |
||
| 79 | $path = []; |
||
| 80 | return true; |
||
| 81 | } else { |
||
| 82 | // Get the entity type of the parameter, treat the rest of the path as a sequence of navprops. |
||
| 83 | assert($parameter instanceof IFunctionParameter); |
||
| 84 | /** |
||
| 85 | * @var IEntityType $entityType |
||
| 86 | */ |
||
| 87 | $entityType = Helpers::getPathSegmentEntityType($parameter->getType()); |
||
| 88 | /** |
||
| 89 | * @var INavigationProperty[] $pathList |
||
| 90 | */ |
||
| 91 | $pathList = []; |
||
| 92 | for ($i = 1; $i < $numSegments; ++$i) { |
||
| 93 | $segment = $pathToResolve[$i]; |
||
| 94 | if (EdmUtil::isQualifiedName($segment)) { |
||
| 95 | if ($i == count($pathToResolve) - 1) { |
||
| 96 | // The last segment must not be type cast. |
||
| 97 | return false; |
||
| 98 | } |
||
| 99 | /** |
||
| 100 | * @var IEntityType|null $subType ; |
||
| 101 | */ |
||
| 102 | $subType = $model->findDeclaredType($segment); |
||
| 103 | $subType = $subType instanceof IEntityType ? $subType : null; |
||
| 104 | if ($subType == null || !$subType->isOrInheritsFrom($entityType)) { |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | |||
| 108 | $entityType = $subType; |
||
| 109 | } else { |
||
| 110 | $navProp = $entityType->findProperty($segment); |
||
| 111 | $navProp = $navProp instanceof INavigationProperty ? $navProp : null; |
||
| 112 | if ($navProp == null) { |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | $pathList[] = $navProp; |
||
| 117 | $entityType = Helpers::getPathSegmentEntityType($navProp->getType()); |
||
|
|
|||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | $path = $pathList; |
||
| 122 | return true; |
||
| 123 | } |
||
| 131 |