diff_classifier.due   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 23.88 %

Importance

Changes 0
Metric Value
wmc 4
eloc 27
dl 16
loc 67
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A _donothing_func() 0 3 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A InactiveDueCreditCollector._donothing() 3 3 1
A InactiveDueCreditCollector.__repr__() 2 2 1
A InactiveDueCreditCollector.dcite() 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
# emacs: at the end of the file
2
# ex: set sts=4 ts=4 sw=4 et:
3
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
4
"""
5
6
Stub file for a guaranteed safe import of duecredit constructs:  if duecredit
7
is not available.
8
9
To use it, place it into your project codebase to be imported, e.g. copy as
10
11
    cp stub.py /path/tomodule/module/due.py
12
13
Note that it might be better to avoid naming it duecredit.py to avoid shadowing
14
installed duecredit.
15
16
Then use in your code as
17
18
    from .due import due, Doi, BibTeX
19
20
See  https://github.com/duecredit/duecredit/blob/master/README.md for examples.
21
22
Origin:     Originally a part of the duecredit
23
Copyright:  2015-2016  DueCredit developers
24
License:    BSD-2
25
"""
26
from __future__ import absolute_import, division, print_function
27
28
__version__ = '0.0.5'
29
30
31 View Code Duplication
class InactiveDueCreditCollector(object):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
32
    """Just a stub at the Collector which would not do anything"""
33
    def _donothing(self, *args, **kwargs):
34
        """Perform no good and no bad"""
35
        pass
36
37
    def dcite(self, *args, **kwargs):
38
        """If I could cite I would"""
39
        def nondecorating_decorator(func):
40
            return func
41
        return nondecorating_decorator
42
43
    cite = load = add = _donothing
44
45
    def __repr__(self):
46
        return self.__class__.__name__ + '()'
47
48
49
def _donothing_func(*args, **kwargs):
50
    """Perform no good and no bad"""
51
    pass
52
53
54
try:
55
    from duecredit import due, BibTeX, Doi, Url
56
    if 'due' in locals() and not hasattr(due, 'cite'):
57
        raise RuntimeError(
58
            "Imported due lacks .cite. DueCredit is now disabled")
59
except Exception as e:
60
    if type(e).__name__ != 'ImportError':
61
        import logging
62
        logging.getLogger("duecredit").error(
63
            "Failed to import duecredit due to %s" % str(e))
64
    # Initiate due stub
65
    due = InactiveDueCreditCollector()
66
    BibTeX = Doi = Url = _donothing_func
67
68
# Emacs mode definitions
69
# Local Variables:
70
# mode: python
71
# py-indent-offset: 4
72
# tab-width: 4
73
# indent-tabs-mode: nil
74
# End:
75