Completed
Push — master ( f42925...a9e580 )
by Jaspar
19s queued 14s
created

gvm.protocols.gmpv208.entities.results   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 43.96 %

Importance

Changes 0
Metric Value
eloc 34
dl 40
loc 91
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ResultsMixin.get_result() 0 21 2
B ResultsMixin.get_results() 40 40 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2021 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
# pylint:  disable=redefined-builtin
20
21
from typing import Any, Optional
22
23
from gvm.errors import RequiredArgument
24
from gvm.utils import add_filter, to_bool
25
from gvm.xml import XmlCommand
26
27
28
class ResultsMixin:
29
    def get_result(self, result_id: str) -> Any:
30
        """Request a single result
31
32
        Arguments:
33
            result_id: UUID of an existing result
34
35
        Returns:
36
            The response. See :py:meth:`send_command` for details.
37
        """
38
        cmd = XmlCommand("get_results")
39
40
        if not result_id:
41
            raise RequiredArgument(
42
                function=self.get_result.__name__, argument='result_id'
43
            )
44
45
        cmd.set_attribute("result_id", result_id)
46
47
        # for single entity always request all details
48
        cmd.set_attribute("details", "1")
49
        return self._send_xml_command(cmd)
50
51 View Code Duplication
    def get_results(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
52
        self,
53
        *,
54
        filter: Optional[str] = None,
55
        filter_id: Optional[str] = None,
56
        task_id: Optional[str] = None,
57
        note_details: Optional[bool] = None,
58
        override_details: Optional[bool] = None,
59
        details: Optional[bool] = None,
60
    ) -> Any:
61
        """Request a list of results
62
63
        Arguments:
64
            filter: Filter term to use for the query
65
            filter_id: UUID of an existing filter to use for the query
66
            task_id: UUID of task for note and override handling
67
            note_details: If notes are included, whether to include note details
68
            override_details: If overrides are included, whether to include
69
                override details
70
            details: Whether to include additional details of the results
71
72
        Returns:
73
            The response. See :py:meth:`send_command` for details.
74
        """
75
        cmd = XmlCommand("get_results")
76
77
        add_filter(cmd, filter, filter_id)
78
79
        if task_id:
80
            cmd.set_attribute("task_id", task_id)
81
82
        if details is not None:
83
            cmd.set_attribute("details", to_bool(details))
84
        if note_details is not None:
85
            cmd.set_attribute("note_details", to_bool(note_details))
86
87
        if override_details is not None:
88
            cmd.set_attribute("override_details", to_bool(override_details))
89
90
        return self._send_xml_command(cmd)
91