| Conditions | 21 |
| Paths | 17 |
| Total Lines | 91 |
| 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 | $declaringFunction = $functionParameter->getDeclaringFunction(); |
||
| 112 | if ($declaringFunction != null && $declaringFunction instanceof IFunction) { |
||
| 113 | // For all functions with this name declared in the model check if it has |
||
| 114 | // a parameter with this name |
||
| 115 | foreach ($context->getModel()->FindFunctions($declaringFunction->FullName()) as $func) { |
||
| 116 | if ($func->findParameter($functionParameter->getName()) != null) { |
||
| 117 | $foundTarget = true; |
||
| 118 | break; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } else { |
||
| 122 | $declaringFunctionImport = $functionParameter->getDeclaringFunction(); |
||
| 123 | if ($declaringFunctionImport != null && $declaringFunctionImport instanceof IFunctionImport) { |
||
| 124 | $container = $declaringFunctionImport->getContainer(); |
||
| 125 | assert($container instanceof IEntityContainer); |
||
| 126 | foreach ($container->findFunctionImports( |
||
| 127 | $declaringFunctionImport->getName() |
||
| 128 | ) as $currentFunction) { |
||
| 129 | if ($currentFunction->findParameter($functionParameter->getName()) != null) { |
||
| 130 | $foundTarget = true; |
||
| 131 | break; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | // Only validate annotations targeting elements that can be found via the |
||
| 138 | // model API. |
||
| 139 | // E.g. annotations targeting annotations will not be valid without this branch. |
||
| 140 | $foundTarget = true; |
||
| 141 | } |
||
| 142 | return $foundTarget; |
||
| 143 | } |
||
| 145 |