use of com.jetbrains.php.lang.psi.elements.PhpClass in project phpinspectionsea by kalessil.
the class OverridingDeprecatedMethodInspector method buildVisitor.
@Override
@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new BasePhpElementVisitor() {
public void visitPhpMethod(Method method) {
/* do not process un-reportable classes and interfaces - we are searching real tech. debt here */
final PhpClass clazz = method.getContainingClass();
final PsiElement methodName = NamedElementUtil.getNameIdentifier(method);
if (null == methodName || null == clazz) {
return;
}
final String searchMethodName = method.getName();
/* search for deprecated parent methods */
final PhpClass parent = OpenapiResolveUtil.resolveSuperClass(clazz);
final Method parentMethod = null == parent ? null : OpenapiResolveUtil.resolveMethod(parent, searchMethodName);
if (null != parentMethod) {
if (!method.isDeprecated() && parentMethod.isDeprecated()) {
final String message = patternNeedsDeprecation.replace("%m%", searchMethodName);
holder.registerProblem(methodName, message, ProblemHighlightType.LIKE_DEPRECATED);
return;
}
if (method.isDeprecated() && !parentMethod.isDeprecated()) {
final String message = patternDeprecateParent.replace("%m%", searchMethodName);
holder.registerProblem(methodName, message, ProblemHighlightType.WEAK_WARNING);
return;
}
}
/* search for deprecated interface methods */
if (!method.isDeprecated()) {
for (final PhpClass iface : OpenapiResolveUtil.resolveImplementedInterfaces(clazz)) {
final Method ifaceMethod = OpenapiResolveUtil.resolveMethod(iface, searchMethodName);
if (ifaceMethod != null && ifaceMethod.isDeprecated()) {
final String message = patternNeedsDeprecation.replace("%m%", searchMethodName);
holder.registerProblem(methodName, message, ProblemHighlightType.LIKE_DEPRECATED);
return;
}
}
}
}
};
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project phpinspectionsea by kalessil.
the class ProtectedMembersOfFinalClassStrategy method isOverride.
private static boolean isOverride(@NotNull PhpClassMember member, @NotNull PhpClass clazz) {
boolean result = false;
final PhpClass parent = OpenapiResolveUtil.resolveSuperClass(clazz);
if (null != parent) {
final String memberName = member.getName();
final PhpClassMember parentMember = member instanceof Field ? parent.findFieldByName(memberName, ((Field) member).isConstant()) : OpenapiResolveUtil.resolveMethod(parent, memberName);
result = parentMember != null;
}
return result;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project phpinspectionsea by kalessil.
the class ComparableCoreClassesStrategy method isComparableObject.
private static boolean isComparableObject(@NotNull PsiElement operand, @NotNull PhpIndex index) {
/* extract types of operand, check if classes are/inherited from \DateTime */
final Set<String> operandTypes = new HashSet<>();
if (operand instanceof PhpTypedElement) {
final PhpType resolved = OpenapiResolveUtil.resolveType((PhpTypedElement) operand, operand.getProject());
if (resolved != null) {
resolved.filterUnknown().getTypes().forEach(t -> operandTypes.add(Types.getType(t)));
}
}
if (!TypesSemanticsUtil.isNullableObjectInterface(operandTypes)) {
operandTypes.clear();
return false;
}
/* collect classes to check for \DateTime relationship */
final List<PhpClass> operandClasses = new ArrayList<>();
operandTypes.stream().filter(fqn -> fqn.charAt(0) == '\\').forEach(fqn -> operandClasses.addAll(OpenapiResolveUtil.resolveClassesAndInterfacesByFQN(fqn, index)));
operandTypes.clear();
/* inspect classes for being a/child of special once */
for (final PhpClass clazz : operandClasses) {
final HashSet<PhpClass> hierarchy = InterfacesExtractUtil.getCrawlInheritanceTree(clazz, true);
for (final PhpClass oneClass : hierarchy) {
if (comparableObjects.contains(oneClass.getFQN())) {
return true;
}
}
hierarchy.clear();
}
operandClasses.clear();
return false;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project yii2support by nvlad.
the class ObjectFactoryReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
PsiElement possibleArrayCreation = myElement.getParent().getParent().getParent();
if (possibleArrayCreation instanceof ArrayCreationExpression) {
ArrayCreationExpression arrayCreation = (ArrayCreationExpression) possibleArrayCreation;
PsiDirectory dir = myElement.getContainingFile().getContainingDirectory();
PhpClass phpClass = ObjectFactoryUtils.findClassByArrayCreation(arrayCreation, dir);
if (phpClass != null) {
PsiElement field = ClassUtils.findWritableField(phpClass, myElement.getText());
return field;
}
}
return null;
}
use of com.jetbrains.php.lang.psi.elements.PhpClass in project yii2support by nvlad.
the class MissingActiveRecordInActiveQueryInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean isOnTheFly) {
return new PhpElementVisitor() {
@Override
public void visitPhpClass(PhpClass clazz) {
if (clazz.getSuperClass() != null && clazz.getSuperClass().getFQN().equals("\\yii\\db\\ActiveQuery")) {
PhpIndex index = PhpIndex.getInstance(clazz.getProject());
PhpClass activeRecordClass = ClassUtils.findClassInSeeTags(index, clazz, "\\yii\\db\\BaseActiveRecord");
if (activeRecordClass == null) {
problemsHolder.registerProblem(clazz.getFirstChild(), "Can not find connected ActiveRecord class.\nYou should add @see tag with linked ActiveRecord", ProblemHighlightType.WEAK_WARNING);
}
}
super.visitPhpClass(clazz);
}
};
}
Aggregations