Conditions | 11 |
Total Lines | 59 |
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:
Complex classes like things3_to_kanban.write_html_column() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | #!/usr/bin/env python3 |
||
99 | def write_html_column(uid, file, header, sql): |
||
100 | """Create a column in the output.""" |
||
101 | |||
102 | sql = """ |
||
103 | SELECT DISTINCT |
||
104 | TASK.uuid, |
||
105 | TASK.title, |
||
106 | CASE |
||
107 | WHEN AREA.title IS NOT NULL THEN AREA.title |
||
108 | WHEN PROJECT.title IS NOT NULL THEN PROJECT.title |
||
109 | WHEN HEADING.title IS NOT NULL THEN HEADING.title |
||
110 | END, |
||
111 | CASE |
||
112 | WHEN AREA.uuid IS NOT NULL THEN AREA.uuid |
||
113 | WHEN PROJECT.uuid IS NOT NULL THEN PROJECT.uuid |
||
114 | END, |
||
115 | CASE |
||
116 | WHEN TASK.recurrenceRule IS NULL |
||
117 | THEN date(TASK.dueDate,"unixepoch") |
||
118 | ELSE NULL |
||
119 | END |
||
120 | FROM |
||
121 | TMTask AS TASK |
||
122 | LEFT JOIN |
||
123 | TMTaskTag TAGS ON TAGS.tasks = TASK.uuid |
||
124 | LEFT OUTER JOIN |
||
125 | TMTask PROJECT ON TASK.project = PROJECT.uuid |
||
126 | LEFT OUTER JOIN |
||
127 | TMArea AREA ON TASK.area = AREA.uuid |
||
128 | LEFT OUTER JOIN |
||
129 | TMTask HEADING ON TASK.actionGroup = HEADING.uuid |
||
130 | WHERE """ + sql |
||
131 | CURSOR.execute(sql) |
||
132 | rows = CURSOR.fetchall() |
||
133 | |||
134 | file.write('<div id="left' + str(uid) + '"><div class="inner"><h2>' + |
||
135 | header + ' <span class="size">' + |
||
136 | str(len(rows)) + '</span></h2>') |
||
137 | |||
138 | for row in rows: |
||
139 | task_uuid = str(row[0]) if row[0] is not None else '' |
||
140 | task_title = anonymize(str(row[1])) if row[1] is not None else '' |
||
141 | context_title = anonymize(str(row[2])) if row[2] is not None else '' |
||
142 | context_uuid = str(row[3]) if row[3] is not None else '' |
||
143 | deadline = str(row[4]) if row[4] is not None else '' |
||
144 | |||
145 | task_link = '<a href="things:///show?id=' + task_uuid + '">' + \ |
||
146 | task_title + '</a>' if task_uuid != '' else task_title |
||
147 | context_link = '<a href="things:///show?id=' + context_uuid + '">' + \ |
||
148 | context_title + '</a>' if context_uuid != '' else context_title |
||
149 | css_class = 'hasProject' if context_title != '' else 'hasNoProject' |
||
150 | css_class = 'hasDeadline' if deadline != '' else css_class |
||
151 | |||
152 | file.write('<div id="box">' + task_link + |
||
153 | '<div class="deadline">' + deadline + '</div>' + |
||
154 | '<div class="area ' + css_class + '">' + context_link + |
||
155 | '</div>' + |
||
156 | '</div>') |
||
157 | file.write("</div></div>") |
||
158 | |||
215 |