All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S107.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

Why is this an issue?

Procedures with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.

Sub SetCoordinates(x1 As Integer, y1 As Integer, z1 As Integer, x2 As Integer, y2 As Integer, z2 As Integer) ' Noncompliant
    ' ...
End Sub

The solution can be to:

  • Split the procedure into smaller ones
' Each function does a part of what the original setCoordinates function was doing, so confusion risks are lower
Sub SetOrigin(x As Integer, y As Integer, z As Integer)
   ' ...
End Sub

Sub SetSize(width As Integer, height As Integer, depth As Integer)
   ' ...
End Sub
  • Find a better data structure for the parameters that group data in a way that makes sense for the specific application domain
Class Point ' In geometry, Point is a logical structure to group data

    Public x As Integer
    Public y As Integer
    Public z As Integer

End Class

Sub SetCoordinates(p1 As Point, p2 As Point)
    ' ...
End Sub

This rule raises an issue when a procedure has more parameters than the provided threshold.

Exceptions

The rule does not count the parameters intended for a base class constructor.

With a maximum number of 4 parameters:

Class BaseClass

    Sub New(Param1 As Integer)
        ' ...
    End Sub

End Class

Class DerivedClass
    Inherits BaseClass

    Public Sub New(Param1 As Integer, Param2 As Integer, Param3 As Integer, Param4 As Integer, Param5 As Long)
    ' Compliant by exception: Param1 is used in the base class constructor, so it does not count in the sum of the parameter list.
        MyBase.New(Param1)
        ' ...
    End Sub

End Class




© 2015 - 2025 Weber Informatics LLC | Privacy Policy