Conditions | 6 |
Total Lines | 54 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | # -*- coding: utf-8 -*- |
||
49 | def get_report( |
||
50 | self, |
||
51 | report_id: str, |
||
52 | *, |
||
53 | filter: Optional[str] = None, |
||
54 | filter_id: Optional[str] = None, |
||
55 | delta_report_id: Optional[str] = None, |
||
56 | report_format_id: Optional[Union[str, ReportFormatType]] = None, |
||
57 | ignore_pagination: Optional[bool] = None, |
||
58 | details: Optional[bool] = True, |
||
59 | ) -> Any: |
||
60 | """Request a single report |
||
61 | |||
62 | Arguments: |
||
63 | report_id: UUID of an existing report |
||
64 | filter: Filter term to use to filter results in the report |
||
65 | filter_id: UUID of filter to use to filter results in the report |
||
66 | delta_report_id: UUID of an existing report to compare report to. |
||
67 | report_format_id: UUID of report format to use |
||
68 | or ReportFormatType (enum) |
||
69 | ignore_pagination: Whether to ignore the filter terms "first" and |
||
70 | "rows". |
||
71 | details: Request additional report information details |
||
72 | defaults to True |
||
73 | |||
74 | Returns: |
||
75 | The response. See :py:meth:`send_command` for details. |
||
76 | """ |
||
77 | cmd = XmlCommand("get_reports") |
||
78 | |||
79 | if not report_id: |
||
80 | raise RequiredArgument( |
||
81 | function=self.get_report.__name__, argument='report_id' |
||
82 | ) |
||
83 | |||
84 | cmd.set_attribute("report_id", report_id) |
||
85 | |||
86 | add_filter(cmd, filter, filter_id) |
||
87 | |||
88 | if delta_report_id: |
||
89 | cmd.set_attribute("delta_report_id", delta_report_id) |
||
90 | |||
91 | if report_format_id: |
||
92 | if isinstance(report_format_id, ReportFormatType): |
||
93 | report_format_id = report_format_id.value |
||
94 | |||
95 | cmd.set_attribute("format_id", report_format_id) |
||
96 | |||
97 | if ignore_pagination is not None: |
||
98 | cmd.set_attribute("ignore_pagination", to_bool(ignore_pagination)) |
||
99 | |||
100 | cmd.set_attribute("details", to_bool(details)) |
||
101 | |||
102 | return self._send_xml_command(cmd) |
||
103 | |||
190 |