SR.SR.__init__()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 67
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 63
nop 30
dl 0
loc 67
rs 7.2775
c 0
b 0
f 0

How to fix   Long Method    Many Parameters   

Long Method

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:

Many Parameters

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
from datetime import datetime
2
3
4
class SR:
5
    # TODO: break down the member variables into smaller classes
6
    def __init__(
7
        self,
8
        country_code_iso: str,
9
        company_code_uic: int,
10
        internal_id: str | None,
11
        decision_id: str | None,
12
        in_timetable: bool,
13
        due_to_railway_features: bool,
14
        line: str,
15
        metre_post_from: int,
16
        metre_post_to: int,
17
        station_from: str,
18
        station_to: str | None,
19
        on_main_track: bool,
20
        main_track_side: str | None,
21
        station_track_switch_source_text: str | None,
22
        station_track_from: str | None,
23
        station_switch_from: str | None,
24
        station_switch_to: str | None,
25
        operating_speed: int,
26
        reduced_speed: int,
27
        reduced_speed_for_mus: int,
28
        not_signalled_from_start_point: bool | None,
29
        not_signalled_from_end_point: bool | None,
30
        cause_source_text: str | None,
31
        cause_categories: str | None,
32
        time_from: datetime,
33
        work_to_be_done: str | None,
34
        time_to: datetime | None,
35
        comment: str | None,
36
        sr_id: str | None = None,
37
    ):
38
        self.id = sr_id
39
        self.country_code_iso = country_code_iso
40
        self.company_code_uic = company_code_uic
41
        self.internal_id = internal_id
42
        self.decision_id = decision_id
43
        self.in_timetable = in_timetable
44
        self.due_to_railway_features = (
45
            due_to_railway_features if not NotImplemented else None
46
        )
47
        self.line = line
48
        self.metre_post_from = metre_post_from
49
        self.metre_post_to = metre_post_to
50
        self.station_from = station_from
51
        self.station_to = station_to
52
        self.on_main_track = on_main_track
53
        self.main_track_side = main_track_side
54
        self.station_track_switch_source_text = station_track_switch_source_text
55
        self.station_track_from = station_track_from
56
        self.station_switch_from = station_switch_from if not NotImplemented else None
57
        self.station_switch_to = station_switch_to if not NotImplemented else None
58
        self.operating_speed = operating_speed
59
        self.reduced_speed = reduced_speed
60
        self.reduced_speed_for_mus = reduced_speed_for_mus
61
        self.not_signalled_from_start_point = (
62
            not_signalled_from_start_point if not NotImplemented else None
63
        )
64
        self.not_signalled_from_end_point = (
65
            not_signalled_from_end_point if not NotImplemented else None
66
        )
67
        self.cause_source_text = cause_source_text
68
        self.cause_categories = cause_categories
69
        self.time_from = time_from
70
        self.work_to_be_done = work_to_be_done
71
        self.time_to = time_to
72
        self.comment = comment
73