motom001/DoorPi

View on GitHub
doorpi/status/status_lib/sipphone.py

Summary

Maintainability
D
1 day
Test Coverage

Function get has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

def get(*args, **kwargs):
    try:
        if len(kwargs['name']) == 0: kwargs['name'] = ['']
        if len(kwargs['value']) == 0: kwargs['value'] = ['']

Severity: Minor
Found in doorpi/status/status_lib/sipphone.py - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Refactor this function to reduce its Cognitive Complexity from 46 to the 15 allowed.
Open

def get(*args, **kwargs):

Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

See

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if name_requested in 'video_enable':
                if len(sipphone.video_codecs) and len(sipphone.video_devices):
                    status['video_enable'] = True
                else:
                    status['video_enable'] = False
Severity: Major
Found in doorpi/status/status_lib/sipphone.py and 1 other location - About 2 hrs to fix
doorpi/status/status_lib/sipphone.py on lines 28..32

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 54.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if name_requested in 'sound_enable':
                if len(sipphone.sound_codecs) and len(sipphone.sound_devices):
                    status['sound_enable'] = True
                else:
                    status['sound_enable'] = False
Severity: Major
Found in doorpi/status/status_lib/sipphone.py and 1 other location - About 2 hrs to fix
doorpi/status/status_lib/sipphone.py on lines 39..43

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 54.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 7 locations. Consider refactoring.
Open

    try:
        if len(kwargs['name']) == 0: kwargs['name'] = ['']
        if len(kwargs['value']) == 0: kwargs['value'] = ['']

        sipphone = kwargs['DoorPiObject'].sipphone
Severity: Major
Found in doorpi/status/status_lib/sipphone.py and 6 other locations - About 1 hr to fix
doorpi/status/status_lib/config.py on lines 9..26
doorpi/status/status_lib/environment.py on lines 54..67
doorpi/status/status_lib/event_handler.py on lines 9..37
doorpi/status/status_lib/history_event.py on lines 9..20
doorpi/status/status_lib/history_snapshot.py on lines 13..28
doorpi/status/status_lib/webserver.py on lines 9..38

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 48.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 16 locations. Consider refactoring.
Open

        if len(kwargs['name']) == 0: kwargs['name'] = ['']
Severity: Major
Found in doorpi/status/status_lib/sipphone.py and 15 other locations - About 35 mins to fix
doorpi/status/status_lib/config.py on lines 10..10
doorpi/status/status_lib/config.py on lines 11..11
doorpi/status/status_lib/environment.py on lines 55..55
doorpi/status/status_lib/environment.py on lines 56..56
doorpi/status/status_lib/event_handler.py on lines 10..10
doorpi/status/status_lib/event_handler.py on lines 11..11
doorpi/status/status_lib/history_event.py on lines 10..10
doorpi/status/status_lib/history_event.py on lines 11..11
doorpi/status/status_lib/history_snapshot.py on lines 14..14
doorpi/status/status_lib/history_snapshot.py on lines 15..15
doorpi/status/status_lib/keyboard.py on lines 12..12
doorpi/status/status_lib/keyboard.py on lines 13..13
doorpi/status/status_lib/sipphone.py on lines 11..11
doorpi/status/status_lib/webserver.py on lines 10..10
doorpi/status/status_lib/webserver.py on lines 11..11

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 33.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 16 locations. Consider refactoring.
Open

        if len(kwargs['value']) == 0: kwargs['value'] = ['']
Severity: Major
Found in doorpi/status/status_lib/sipphone.py and 15 other locations - About 35 mins to fix
doorpi/status/status_lib/config.py on lines 10..10
doorpi/status/status_lib/config.py on lines 11..11
doorpi/status/status_lib/environment.py on lines 55..55
doorpi/status/status_lib/environment.py on lines 56..56
doorpi/status/status_lib/event_handler.py on lines 10..10
doorpi/status/status_lib/event_handler.py on lines 11..11
doorpi/status/status_lib/history_event.py on lines 10..10
doorpi/status/status_lib/history_event.py on lines 11..11
doorpi/status/status_lib/history_snapshot.py on lines 14..14
doorpi/status/status_lib/history_snapshot.py on lines 15..15
doorpi/status/status_lib/keyboard.py on lines 12..12
doorpi/status/status_lib/keyboard.py on lines 13..13
doorpi/status/status_lib/sipphone.py on lines 10..10
doorpi/status/status_lib/webserver.py on lines 10..10
doorpi/status/status_lib/webserver.py on lines 11..11

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 33.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Expected 2 blank lines, found 1
Open

def get(*args, **kwargs):
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Separate top-level function and class definitions with two blank lines.

Method definitions inside a class are separated by a single blank
line.

Extra blank lines may be used (sparingly) to separate groups of
related functions.  Blank lines may be omitted between a bunch of
related one-liners (e.g. a set of dummy implementations).

Use blank lines in functions, sparingly, to indicate logical
sections.

Okay: def a():\n    pass\n\n\ndef b():\n    pass
Okay: def a():\n    pass\n\n\nasync def b():\n    pass
Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
Okay: default = 1\nfoo = 1
Okay: classify = 1\nfoo = 1

E301: class Foo:\n    b = 0\n    def bar():\n        pass
E302: def a():\n    pass\n\ndef b(n):\n    pass
E302: def a():\n    pass\n\nasync def b(n):\n    pass
E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
E303: def a():\n\n\n\n    pass
E304: @decorator\n\ndef a():\n    pass
E305: def a():\n    pass\na()
E306: def a():\n    def b():\n        pass\n    def c():\n        pass

Expected 2 blank lines, found 1
Open

def is_active(doorpi_object):
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Separate top-level function and class definitions with two blank lines.

Method definitions inside a class are separated by a single blank
line.

Extra blank lines may be used (sparingly) to separate groups of
related functions.  Blank lines may be omitted between a bunch of
related one-liners (e.g. a set of dummy implementations).

Use blank lines in functions, sparingly, to indicate logical
sections.

Okay: def a():\n    pass\n\n\ndef b():\n    pass
Okay: def a():\n    pass\n\n\nasync def b():\n    pass
Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
Okay: default = 1\nfoo = 1
Okay: classify = 1\nfoo = 1

E301: class Foo:\n    b = 0\n    def bar():\n        pass
E302: def a():\n    pass\n\ndef b(n):\n    pass
E302: def a():\n    pass\n\nasync def b(n):\n    pass
E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
E303: def a():\n\n\n\n    pass
E304: @decorator\n\ndef a():\n    pass
E305: def a():\n    pass\na()
E306: def a():\n    def b():\n        pass\n    def c():\n        pass

Line too long (81 > 79 characters)
Open

        return {'Error': 'could not create '+str(__name__)+' object - '+str(exp)}
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Limit all lines to a maximum of 79 characters.

There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side.  The default wrapping on such
devices looks ugly.  Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.

Reports error E501.

Multiple statements on one line (colon)
Open

        if len(kwargs['value']) == 0: kwargs['value'] = ['']
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Compound statements (on the same line) are generally discouraged.

While sometimes it's okay to put an if/for/while with a small body
on the same line, never do this for multi-clause statements.
Also avoid folding such long lines!

Always use a def statement instead of an assignment statement that
binds a lambda expression directly to a name.

Okay: if foo == 'blah':\n    do_blah_thing()
Okay: do_one()
Okay: do_two()
Okay: do_three()

E701: if foo == 'blah': do_blah_thing()
E701: for x in lst: total += x
E701: while t < 10: t = delay()
E701: if foo == 'blah': do_blah_thing()
E701: else: do_non_blah_thing()
E701: try: something()
E701: finally: cleanup()
E701: if foo == 'blah': one(); two(); three()
E702: do_one(); do_two(); do_three()
E703: do_four();  # useless semicolon
E704: def f(x): return 2*x
E731: f = lambda x: 2*x

Line too long (97 > 79 characters)
Open

                    status['recorder_parsed_filename'] = sipphone.recorder.parsed_record_filename
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Limit all lines to a maximum of 79 characters.

There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side.  The default wrapping on such
devices looks ugly.  Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.

Reports error E501.

Multiple statements on one line (colon)
Open

        if len(kwargs['name']) == 0: kwargs['name'] = ['']
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Compound statements (on the same line) are generally discouraged.

While sometimes it's okay to put an if/for/while with a small body
on the same line, never do this for multi-clause statements.
Also avoid folding such long lines!

Always use a def statement instead of an assignment statement that
binds a lambda expression directly to a name.

Okay: if foo == 'blah':\n    do_blah_thing()
Okay: do_one()
Okay: do_two()
Okay: do_three()

E701: if foo == 'blah': do_blah_thing()
E701: for x in lst: total += x
E701: while t < 10: t = delay()
E701: if foo == 'blah': do_blah_thing()
E701: else: do_non_blah_thing()
E701: try: something()
E701: finally: cleanup()
E701: if foo == 'blah': one(); two(); three()
E702: do_one(); do_two(); do_three()
E703: do_four();  # useless semicolon
E704: def f(x): return 2*x
E731: f = lambda x: 2*x

Line too long (83 > 79 characters)
Open

                    status['recorder_filename'] = sipphone.recorder.record_filename
Severity: Minor
Found in doorpi/status/status_lib/sipphone.py by pep8

Limit all lines to a maximum of 79 characters.

There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side.  The default wrapping on such
devices looks ugly.  Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.

Reports error E501.

There are no issues that match your filters.

Category
Status