Completed
Pull Request — master (#2609)
by Udayan
02:12
created

ProjectWideBear   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 54
loc 54
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A kind() 3 3 1
A analyze() 12 12 1
A execute_task() 6 6 1
A __init__() 9 9 1
A generate_tasks() 6 6 1
A get_metadata() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
from coalib.bears.Bear import Bear
2
from coalib.bears.BEAR_KIND import BEAR_KIND
3
from coalib.settings.FunctionMetadata import FunctionMetadata
4
5
6 View Code Duplication
class ProjectWideBear(Bear):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Unused Code introduced by
This abstract class does not seem to be used anywhere.
Loading history...
7
    """
8
    A ProjectWideBear is a Bear that analyzes all files at once. This has the
9
    advantage of drawing advanced semantic analysis that give results that are
10
    applicable to the whole codebase.
11
    """
12
13
    def __init__(self,
14
                 file_set,  # A set of file_proxies
15
                 section,
16
                 message_queue,
17
                 timeout=0):
18
        Bear.__init__(self, section, message_queue, timeout)
19
        self.file_set = file_set
20
21
        self.kwargs = self.get_metadata().create_params_from_section(section)
22
23
    @staticmethod
24
    def kind():
25
        return BEAR_KIND.PROJECTWIDE
26
27
    def execute_task(self, task, kwargs):
28
        """
29
        This method is responsible for getting results from the
30
        analysis routines.
31
        """
32
        return list(self.analyze(task, **kwargs))
33
34
    def analyze(self,
35
                file_set,
36
                *args,
37
                dependency_results=None,
38
                **kwargs):
39
        """
40
        Handles the given file.
41
42
        :param file_set:       A set of FileProxy objects.
43
        :return:               A list of Result
44
        """
45
        raise NotImplementedError("This function has to be implemented for a "
46
                                  "runnable bear.")
47
48
    def generate_tasks(self):
49
        """
50
        This method is responsible for providing the files and arguments for
51
        the tasks the bear needs to perform.
52
        """
53
        return [self.file_set, self.kwargs]
54
55
    @classmethod
56
    def get_metadata(cls):
57
        return FunctionMetadata.from_function(
58
            cls.run,
59
            omit={"self", "file_proxy", "dependency_results"})
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...