bilalshaikh42/OASTools

View on GitHub

Showing 111 of 111 total issues

Cyclomatic complexity is too high in method _get_example_from_properties. (7)
Open

    def _get_example_from_properties(self, spec):
        """Get example from the properties of an object defined inline.
        Args:
            prop_spec: property specification you want an example of.
        Returns:
Severity: Minor
Found in oastools/parse/parser.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in function traverse. (6)
Open

def traverse(spec, rootpath, callback=resolve):
    if (isinstance(spec, dict)):
        for key in spec.keys():
            if key == "$ref":
                refSpec = callback(spec[key], rootpath)
Severity: Minor
Found in oastools/resolve/resolver.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function traverse has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def traverse(spec, rootpath, callback=resolve):
    if (isinstance(spec, dict)):
        for key in spec.keys():
            if key == "$ref":
                refSpec = callback(spec[key], rootpath)
Severity: Minor
Found in oastools/resolve/resolver.py - About 1 hr 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

Function get_path_spec has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def get_path_spec(self, path, action=None):
        """Get the specification matching with the given path.
        Args:
            path: path we want the specification.
            action: get the specification for the given action.
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

Function _validate_type has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def _validate_type(self, properties_spec, value):
        """Validate the given value with the given property spec.
        Args:
            properties_dict: specification of the property to check (From definition not route).
            value: value to check.
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

Function _example_from_complex_def has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def _example_from_complex_def(self, prop_spec):
        """Get an example from a property specification.
        In case there is no "type" key in the root of the dictionary.
        Args:
            prop_spec: property specification you want an example of.
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

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

                tag = action['tags'][0] if 'tags' in action.keys(
                ) and action['tags'] else None
Severity: Major
Found in oastools/parse/parser.py and 1 other location - About 1 hr to fix
oastools/parse/parser.py on lines 644..645

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 44.

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 2 locations. Consider refactoring.
Open

                tag = action['tags'][0] if 'tags' in action.keys(
                ) and action['tags'] else None
Severity: Major
Found in oastools/parse/parser.py and 1 other location - About 1 hr to fix
oastools/parse/parser.py on lines 90..91

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 44.

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

Function _get_example_from_properties has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def _get_example_from_properties(self, spec):
        """Get example from the properties of an object defined inline.
        Args:
            prop_spec: property specification you want an example of.
        Returns:
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

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

                        if 'type' in spec['schema'].keys() and spec['schema']['type'] == 'array':
Severity: Major
Found in oastools/parse/parser.py and 2 other locations - About 1 hr to fix
oastools/parse/parser.py on lines 449..449
oastools/parse/parser.py on lines 850..850

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 40.

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 3 locations. Consider refactoring.
Open

                    if 'type' in param_spec['schema'].keys() and param_spec['schema']['type'] == 'array':
Severity: Major
Found in oastools/parse/parser.py and 2 other locations - About 1 hr to fix
oastools/parse/parser.py on lines 449..449
oastools/parse/parser.py on lines 964..964

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 40.

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 3 locations. Consider refactoring.
Open

            if 'format' in prop_spec['items'].keys() and prop_spec['items']['format'] == 'date-time':
Severity: Major
Found in oastools/parse/parser.py and 2 other locations - About 1 hr to fix
oastools/parse/parser.py on lines 850..850
oastools/parse/parser.py on lines 964..964

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 40.

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

Function validate_additional_properties has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def validate_additional_properties(self, valid_response, response):
        """Validates additional properties. In additional properties, we only
           need to compare the values of the dict, not the keys
        Args:
            valid_response: An example response (for example generated in
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

Function _validate_post_body has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def _validate_post_body(actual_request_body, body_specification):
        """ returns a tuple (boolean, msg)
            to indicate whether the validation passed
            if False then msg contains the reason
            if True then msg is empty
Severity: Minor
Found in oastools/parse/parser.py - About 1 hr 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

Function _definition_from_example has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def _definition_from_example(example):
        """Generates a swagger definition json from a given example
           Works only for simple types in the dict
        Args:
            example: The example for which we want a definition
Severity: Minor
Found in oastools/parse/parser.py - About 55 mins 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

Function get_request_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def get_request_data(self, path, action, body=None):
        """Get the default data and status code of the given path + action request.
        Args:
            path: path of the request.
            action: action of the request(get, post, delete...)
Severity: Minor
Found in oastools/parse/parser.py - About 55 mins 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

Function check_type has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def check_type(value, type_def):
        """Check if the value is in the type given in type_def.
        Args:
            value: the var to test.
            type_def: string representing the type in swagger.
Severity: Minor
Found in oastools/parse/parser.py - About 55 mins 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

Function build_one_definition_example has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def build_one_definition_example(self, def_name):
        """Build the example for the given definition.
        Args:
            def_name: Name of the definition.
        Returns:
Severity: Minor
Found in oastools/parse/parser.py - About 45 mins 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

Avoid deeply nested control flow statements.
Open

                        if 'type' in spec['schema'].keys() and spec['schema']['type'] == 'array':
                                # It is an array
                                # Get value from definition
                            if '$ref' in spec['schema']['items']:
                                definition_name = self.get_definition_name_from_ref(spec['schema']
Severity: Major
Found in oastools/parse/parser.py - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                        if len(body) > 0 and not self.validate_definition(definition_name, body[0]):
                            msg = "The body did not validate against its definition"
                            return False, msg
                    elif ('type' in param_spec['schema'].keys() and not
Severity: Major
Found in oastools/parse/parser.py - About 45 mins to fix
Severity
Category
Status
Source
Language