Conditions | 19 |
Paths | 15 |
Total Lines | 90 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
52 | protected function findTarget( |
||
53 | ValidationContext $context, |
||
54 | \AlgoWeb\ODataMetadata\Interfaces\IVocabularyAnnotatable $target |
||
55 | ): bool { |
||
56 | $foundTarget = false; |
||
57 | $entityContainer = $target; |
||
58 | if ($entityContainer instanceof IEntityContainer) { |
||
59 | $foundTarget = ($context->getModel()->findEntityContainer($entityContainer->FullName()) != null); |
||
60 | return $foundTarget; |
||
61 | } |
||
62 | $entitySet = $target; |
||
63 | if ($entitySet instanceof IEntitySet) { |
||
64 | $container = $entitySet->getContainer(); |
||
65 | if ($container != null && $container instanceof IEntityContainer) { |
||
66 | $foundTarget = ($container->findEntitySet($entitySet->getName()) != null); |
||
|
|||
67 | return $foundTarget; |
||
68 | } |
||
69 | return false; |
||
70 | } |
||
71 | $schemaType = $target; |
||
72 | if ($schemaType instanceof ISchemaType) { |
||
73 | $foundTarget = ($context->getModel()->FindType($schemaType->FullName()) != null); |
||
74 | return $foundTarget; |
||
75 | } |
||
76 | $term = $target; |
||
77 | if ($term instanceof ITerm) { |
||
78 | $foundTarget = ($context->getModel()->FindValueTerm($term->FullName()) != null); |
||
79 | return $foundTarget; |
||
80 | } |
||
81 | $function = $target; |
||
82 | if ($function instanceof IFunction) { |
||
83 | $foundTarget = count($context->getModel()->FindFunctions($function->FullName())) > 0; |
||
84 | return $foundTarget; |
||
85 | } |
||
86 | $functionImport = $target; |
||
87 | EdmUtil::checkArgumentNull($functionImport->getName(), 'functionImport->getName'); |
||
88 | if ($functionImport instanceof IFunctionImport) { |
||
89 | $funcName = $functionImport->getName(); |
||
90 | $foundTarget = count($functionImport->getContainer()->findFunctionImports($funcName)) > 0; |
||
91 | return $foundTarget; |
||
92 | } |
||
93 | $typeProperty = $target; |
||
94 | if ($typeProperty instanceof IProperty) { |
||
95 | $declaringType = $typeProperty->getDeclaringType(); |
||
96 | assert($declaringType instanceof ISchemaType); |
||
97 | $declaringTypeFullName = EdmUtil::FullyQualifiedName($declaringType); |
||
98 | EdmUtil::checkArgumentNull($declaringTypeFullName, 'declaringTypeFullName'); |
||
99 | EdmUtil::checkArgumentNull($typeProperty->getName(), 'typeProperty->getName'); |
||
100 | $modelType = $context->getModel()->FindType($declaringTypeFullName); |
||
101 | if ($modelType !== null && $modelType instanceof IStructuredType) { |
||
102 | // If we can find a structured type with this name in the model check if it |
||
103 | // has a property with this name |
||
104 | $foundTarget = ($modelType->findProperty($typeProperty->getName()) != null); |
||
105 | return $foundTarget; |
||
106 | } |
||
107 | return false; |
||
108 | } |
||
109 | $functionParameter = $target; |
||
110 | if ($functionParameter instanceof IFunctionParameter) { |
||
111 | $paramName = $functionParameter->getName(); |
||
112 | $declaringFunction = $functionParameter->getDeclaringFunction(); |
||
113 | if ($declaringFunction != null && $declaringFunction instanceof IFunction) { |
||
114 | // For all functions with this name declared in the model check if it has |
||
115 | // a parameter with this name |
||
116 | $functions = $context->getModel()->FindFunctions($declaringFunction->FullName()); |
||
117 | return 0 < count(array_filter($functions, function (IFunction $func) use ($paramName) { |
||
118 | return null !== $func->findParameter($paramName); |
||
119 | })); |
||
120 | } else { |
||
121 | $declaringFunctionImport = $functionParameter->getDeclaringFunction(); |
||
122 | if ($declaringFunctionImport != null && $declaringFunctionImport instanceof IFunctionImport) { |
||
123 | $container = $declaringFunctionImport->getContainer(); |
||
124 | assert($container instanceof IEntityContainer); |
||
125 | foreach ($container->findFunctionImports( |
||
126 | $declaringFunctionImport->getName() |
||
127 | ) as $currentFunction) { |
||
128 | if ($currentFunction->findParameter($functionParameter->getName()) != null) { |
||
129 | $foundTarget = true; |
||
130 | break; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | } else { |
||
136 | // Only validate annotations targeting elements that can be found via the |
||
137 | // model API. |
||
138 | // E.g. annotations targeting annotations will not be valid without this branch. |
||
139 | $foundTarget = true; |
||
140 | } |
||
141 | return $foundTarget; |
||
142 | } |
||
144 |