/** array('foo' => 'bar', 'foo1' => 'bar', 1 => 'foo') */ public static HashMap<String, String> getArrayKeyValueMap( @NotNull ArrayCreationExpression arrayCreationExpression) { HashMap<String, String> keys = new HashMap<String, String>(); for (ArrayHashElement arrayHashElement : arrayCreationExpression.getHashElements()) { PhpPsiElement child = arrayHashElement.getKey(); if (child != null && ((child instanceof StringLiteralExpression) || PhpPatterns.psiElement(PhpElementTypes.NUMBER).accepts(child))) { String key; if (child instanceof StringLiteralExpression) { key = ((StringLiteralExpression) child).getContents(); } else { key = child.getText(); } if (StringUtils.isBlank(key)) { continue; } String value = null; if (arrayHashElement.getValue() instanceof StringLiteralExpression) { value = ((StringLiteralExpression) arrayHashElement.getValue()).getContents(); } keys.put(key, value); } } return keys; }
private static void attachOnDefaultOptions( Project project, HashMap<String, String> defaultValues, String typeClass) { PsiElement setDefaultOptions = PhpElementsUtil.getPsiElementsBySignatureSingle( project, "#M#C\\" + typeClass + ".setDefaultOptions"); if (setDefaultOptions == null) { return; } Collection<MethodReference> tests = PsiTreeUtil.findChildrenOfType(setDefaultOptions, MethodReference.class); for (MethodReference methodReference : tests) { // instance check // methodReference.getSignature().equals("#M#C\\Symfony\\Component\\OptionsResolver\\OptionsResolverInterface.setDefaults") if (PhpElementsUtil.isEqualMethodReferenceName(methodReference, "setDefaults")) { PsiElement[] parameters = methodReference.getParameters(); if (parameters.length > 0 && parameters[0] instanceof ArrayCreationExpression) { for (String key : PhpElementsUtil.getArrayCreationKeys((ArrayCreationExpression) parameters[0])) { defaultValues.put(key, typeClass); } } } // support: parent::setDefaultOptions($resolver) // Symfony\Component\Form\Extension\Core\Type\FormType:setDefaultOptions if (PhpElementsUtil.isEqualMethodReferenceName(methodReference, "setDefaultOptions") && methodReference.getReferenceType() == PhpModifier.State.PARENT) { PsiElement parentMethod = PhpElementsUtil.getPsiElementsBySignatureSingle( project, methodReference.getSignature()); if (parentMethod instanceof Method) { PhpClass phpClass = ((Method) parentMethod).getContainingClass(); if (phpClass != null) { attachOnDefaultOptions(project, defaultValues, phpClass.getPresentableFQN()); } } } } }