Conditions | 7 |
Total Lines | 30 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 .base import Resource |
||
12 | def create(self, |
||
13 | ticket_id: int, |
||
14 | content: str, |
||
15 | cc: str = None, |
||
16 | bcc: str = None, |
||
17 | attachment_ids: str = None, |
||
18 | on_behalf_of_id: str = None, |
||
19 | on_behalf_of_email: str = None, |
||
20 | notify_requester: str = False, |
||
21 | content_as_html: bool = False): |
||
22 | reply = { |
||
23 | "content": { |
||
24 | "html" if content_as_html else "text": content, |
||
25 | }, |
||
26 | "notify_requester": notify_requester |
||
27 | } |
||
28 | |||
29 | if cc is not None: |
||
30 | reply["cc"] = cc |
||
31 | if bcc is not None: |
||
32 | reply["bcc"] = bcc |
||
33 | if attachment_ids is not None: |
||
34 | reply["content"]["attachment_ids"] = attachment_ids |
||
35 | |||
36 | if on_behalf_of_id is not None: |
||
37 | reply["on_behalf_of"] = {"id": on_behalf_of_id} |
||
38 | elif on_behalf_of_email is not None: |
||
39 | reply["on_behalf_of"] = {"email": on_behalf_of_email} |
||
40 | |||
41 | return self._post("/tickets/{ticket_id}/replies".format(ticket_id=ticket_id), data={"reply": reply}) |
||
42 | |||
47 |