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