File codegen.py
has 3092 lines of code (exceeds 250 allowed). Consider refactoring. Open
# -*- Mode: Python -*-
# GDBus - GLib D-Bus Library
#
# Copyright (C) 2008-2011 Red Hat, Inc.
Function declare_types
has a Cognitive Complexity of 176 (exceeds 5 allowed). Consider refactoring. Open
def declare_types(self):
for i in self.ifaces:
self.h.write('\n')
self.h.write('/* ------------------------------------------------------------------------ */\n')
self.h.write('/* Declarations for %s */\n'%i.name)
- Read upRead up
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
Function generate_interface
has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring. Open
def generate_interface(self, i):
self.c.write('\n')
self.c.write(self.docbook_gen.expand(
'/**\n'
- Read upRead up
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
Function generate_introspection_for_interface
has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring. Open
def generate_introspection_for_interface(self, i):
self.c.write('/* ---- Introspection data for %s ---- */\n'
'\n'%(i.name))
if len(i.methods) > 0:
- Read upRead up
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
Function generate_method_calls
has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring. Open
def generate_method_calls(self, i):
for m in i.methods:
unix_fd = False
if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
unix_fd = True
- Read upRead up
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
Function generate_proxy
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def generate_proxy(self, i):
# class boilerplate
self.c.write('/* ------------------------------------------------------------------------ */\n'
'\n')
- Read upRead up
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
Function generate_method_completers
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def generate_method_completers(self, i):
for m in i.methods:
unix_fd = False
if utils.lookup_annotation(m.annotations, 'org.gtk.GDBus.C.UnixFD'):
unix_fd = True
- Read upRead up
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
Function generate_object
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_object(self):
self.c.write('/* ------------------------------------------------------------------------\n'
' * Code for Object, ObjectProxy and ObjectSkeleton\n'
' * ------------------------------------------------------------------------\n'
' */\n'
Function generate_skeleton
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_skeleton(self, i):
# class boilerplate
self.c.write('/* ------------------------------------------------------------------------ */\n'
'\n')
Function generate_property_accessors
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def generate_property_accessors(self, i):
for p in i.properties:
# getter
if p.readable and p.writable:
hint = 'Since this D-Bus property is both readable and writable, it is meaningful to use this function on both the client- and service-side.'
- Read upRead up
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
Function generate_skeleton
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def generate_skeleton(self, i):
# class boilerplate
self.c.write('/* ------------------------------------------------------------------------ */\n'
'\n')
- Read upRead up
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
Function generate_proxy
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_proxy(self, i):
# class boilerplate
self.c.write('/* ------------------------------------------------------------------------ */\n'
'\n')
Function generate_object_manager_client
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_object_manager_client(self):
self.c.write('/* ------------------------------------------------------------------------\n'
' * Code for ObjectManager client\n'
' * ------------------------------------------------------------------------\n'
' */\n'
Function generate_annotations
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def generate_annotations(self, prefix, annotations):
if annotations == None:
return
n = 0
- Read upRead up
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
Function generate_args
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def generate_args(self, prefix, args):
for a in args:
num_anno = self.generate_annotations('%s_arg_%s_annotation_info'%(prefix, a.name), a.annotations)
self.c.write('static const _ExtendedGDBusArgInfo %s_%s =\n'
- Read upRead up
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
Function generate_object
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def generate_object(self):
self.c.write('/* ------------------------------------------------------------------------\n'
' * Code for Object, ObjectProxy and ObjectSkeleton\n'
' * ------------------------------------------------------------------------\n'
' */\n'
- Read upRead up
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
Function __init__
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(self, ifaces, namespace, interface_prefix, generate_objmanager, docbook_gen, h, c):
Function write_gtkdoc_deprecated_and_since_and_close
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def write_gtkdoc_deprecated_and_since_and_close(self, obj, f, indent):
if len(obj.since) > 0:
f.write('%*s *\n'
'%*s * Since: %s\n'
%(indent, '', indent, '', obj.since))
- Read upRead up
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
Avoid deeply nested control flow statements. Open
if p.deprecated:
self.h.write('G_GNUC_DEPRECATED ')
self.h.write('%s%s_dup_%s (%s *object);\n'%(p.arg.ctype_in_dup, i.name_lower, p.name_lower, i.camel_name))
Function generate_signal_emitters
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def generate_signal_emitters(self, i):
for s in i.signals:
self.c.write(self.docbook_gen.expand(
'/**\n'
' * %s_emit_%s:\n'
- Read upRead up
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
- Read upRead up
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 19113.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76