Showing 25 of 25 total issues
File test_rating.py
has 572 lines of code (exceeds 250 allowed). Consider refactoring. Open
import datetime
import json
import time
import unittest
from unittest.mock import patch, MagicMock, Mock, PropertyMock, mock_open
File results.py
has 381 lines of code (exceeds 250 allowed). Consider refactoring. Open
import datetime
import json
import os
from typing import Optional, TYPE_CHECKING, Union, TypedDict, List, Any
File test_results.py
has 328 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""
Tests for the results module.
This tests can be improved. These tests do not verify the returned outputs.
"""
Function poetry_version
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def poetry_version(version: Union[str, dict, None]) -> str:
"""Convert Poetry version to PEP440 version."""
if version is None:
return ""
if isinstance(version, dict):
- 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
File rating.py
has 281 lines of code (exceeds 250 allowed). Consider refactoring. Open
import datetime
import json
import os
import logging
from functools import cached_property
Identical blocks of code found in 2 locations. Consider refactoring. Open
@unittest.skipIf(sys.version_info >= (3, 11), "Test for Python 3.10 or lower")
def test_python_310_or_lower(self):
expected_dt = datetime.datetime(
2023, 9, 14, 18, 56, 29, 702900, tzinfo=datetime.timezone.utc
)
- 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 50.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
@unittest.skipIf(sys.version_info < (3, 11), "Test for Python 3.11 or higher")
def test_python_311_or_higher(self):
expected_dt = datetime.datetime(
2023, 9, 14, 18, 56, 29, 702900, tzinfo=datetime.timezone.utc
)
- 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 50.
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
Function show_packages_results
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def show_packages_results(self, dependencies: "Dependencies"):
global_rating_score = self.get_global_rating_score(dependencies)
for package in dependencies.packages.values():
if package.name not in dependencies.req_file:
continue
- 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
Consider simplifying this complex logical expression. Open
if (
e.response is not None
and e.response.status_code == 403
and e.response.reason == "rate limit exceeded"
and not github_token
Function action
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def action(
Function find_in_directory
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def find_in_directory(cls, directory: Union[str, Path]) -> Optional["ReqFileBase"]:
"""Find requirement file in the given directory."""
if isinstance(directory, str):
directory = Path(directory)
for requirements_file in REQUIREMENTS_FILES:
- 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 analyze_file
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def analyze_file(
Function search_in_readme
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def search_in_readme(content: str, package_name: str) -> Optional[bool]:
"""Search for patterns in readme. If found the pattern, check if the package name is package_name.
If the package name found is package_name, return True, else continues searching. If after all
patterns are searched and no package name is found, return False. If any pattern matches,
return None.
- 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__(
Function analyze_package
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def analyze_package(
Function test_save_to_cache
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def test_save_to_cache(
Similar blocks of code found in 2 locations. Consider refactoring. Open
def test_repr(self):
"""Test the __repr__ method in the PackageList class."""
package_list = PackageList(["package", "other"])
self.assertEqual("<ReqFile (2)>", repr(package_list))
- 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 35.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def test_str(self):
"""Test the __str__ method in the PackageList class."""
package_list = PackageList(["package", "other"])
self.assertEqual("['package', 'other']", str(package_list))
- 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 35.
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
Function get_github_readme
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_github_readme(owner: str, repo: str) -> str:
"""Get the readme content from GitHub."""
headers = {}
if github_token:
headers["Authorization"] = f"Bearer {github_token}"
- 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 test_save_to_cache
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def test_save_to_cache(