com.github.netkorp.telegram.framework.condition.ExcludeCondition   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 28
rs 10
c 2
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B matches(ConditionContext,AnnotatedTypeMetadata) 0 16 6
1
package com.github.netkorp.telegram.framework.condition;
0 ignored issues
show
Code Smell introduced by
It is a best practice to supply a copyright/licence header in your code. Your organisation probably has a template for that.
Loading history...
2
3
import com.github.netkorp.telegram.framework.annotations.TelegramCommand;
4
import org.springframework.context.annotation.Condition;
5
import org.springframework.context.annotation.ConditionContext;
6
import org.springframework.core.type.AnnotatedTypeMetadata;
7
import org.springframework.core.type.AnnotationMetadata;
8
import org.springframework.core.type.MethodMetadata;
9
import org.springframework.stereotype.Component;
10
11
import java.util.List;
12
import java.util.Map;
13
14
/**
15
 * Searches for the name of every available command in the excluded command list and the command that appears
16
 * in the list will be excluded from the available command list.
17
 */
18
@Component
19
public class ExcludeCondition implements Condition {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
20
21
    /**
22
     * Determine if the condition matches.
23
     *
24
     * @param context  the condition context
25
     * @param metadata metadata of the {@link AnnotationMetadata class}
26
     *                 or {@link MethodMetadata method} being checked
27
     * @return {@code true} if the condition matches and the component can be registered,
28
     * or {@code false} to veto the annotated component's registration
29
     */
30
    @Override
31
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
0 ignored issues
show
Coding Style introduced by
Make this line start at column 3.
Loading history...
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
32
        List excludeValue = context.getEnvironment().getProperty("telegram.commands.exclude", List.class);
0 ignored issues
show
Coding Style introduced by
Make this line start at column 5.
Loading history...
33
        if (excludeValue != null && context.getBeanFactory() != null) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
34
            Map<String, Object> attributes = metadata.getAnnotationAttributes(TelegramCommand.class.getName());
0 ignored issues
show
Coding Style introduced by
Make this line start at column 7.
Loading history...
35
            if (attributes != null) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
36
                String[] commandNames = (String[]) attributes.get("name");
0 ignored issues
show
Coding Style introduced by
Make this line start at column 9.
Loading history...
37
                for (String commandName : commandNames) {
0 ignored issues
show
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
38
                    if (excludeValue.contains(commandName)) {
0 ignored issues
show
Coding Style introduced by
Make this line start at column 11.
Loading history...
Comprehensibility introduced by
Refactor this code to not nest more than 3 if/for/while/switch/try statements.
Loading history...
Coding Style introduced by
Move this left curly brace to the beginning of next line of code.
Loading history...
39
                        return false;
0 ignored issues
show
Coding Style introduced by
Make this line start at column 13.
Loading history...
40
                    }
41
                }
42
            }
43
        }
44
45
        return true;
46
    }
47
}
48