JohnCoates/Aerial

View on GitHub
Aerial/Source/Views/Layers/Weather/ConditionLayer.swift

Summary

Maintainability
C
7 hrs
Test Coverage

Function addWindAndHumidity has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    func addWindAndHumidity(x: CGFloat, y: CGFloat) -> CGFloat {
        // We need to make sure we have the data, and the options are selected
        var addWind = false, addHumidity = false

        let wind = condition?.wind
Severity: Minor
Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift - About 1 hr to fix

    Function makeWindBlock has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func makeWindBlock(wind: OWWind) -> CALayer {
            let windBlock = CALayer()
    
            // Make a vertically centered layer for t°
            let textWind = CAVCTextLayer()
    Severity: Minor
    Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift - About 1 hr to fix

      Function addWindAndHumidity has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          func addWindAndHumidity(x: CGFloat, y: CGFloat) -> CGFloat {
              // We need to make sure we have the data, and the options are selected
              var addWind = false, addHumidity = false
      
              let wind = condition?.wind
      Severity: Minor
      Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid too many return statements within this function.
      Open

              return 0
      Severity: Major
      Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift - About 30 mins to fix

        Force casts should be avoided
        Open

                let rect2 = textWind.calculateRect(string: textWind.string as! String, font: textWind.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect = temp.calculateRect(string: temp.string as! String, font: temp.font as! NSFont, maxWidth: 220)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect = temp.calculateRect(string: temp.string as! String, font: temp.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect2 = textHumidity.calculateRect(string: textHumidity.string as! String, font: textHumidity.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect = temp.calculateRect(string: temp.string as! String, font: temp.font as! NSFont, maxWidth: 220)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect2 = feel.calculateRect(string: feel.string as! String, font: feel.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect = temp.calculateRect(string: temp.string as! String, font: temp.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect2 = feel.calculateRect(string: feel.string as! String, font: feel.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect2 = textHumidity.calculateRect(string: textHumidity.string as! String, font: textHumidity.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Force casts should be avoided
        Open

                let rect2 = textWind.calculateRect(string: textWind.string as! String, font: textWind.font as! NSFont)

        forced-type-cast

        Avoid using the forced form of the type cast operator (as!) because Swift is not able to determine at compile time if the type conversion will succeed. In the event of an unsuccessful conversion, a runtime error will be triggered. The conditional form of the type cast operator (as?) is safer and should be used when possible.

        Preferred

        if let movie = item as? Movie {
            print("Movie: '\(movie.name)', dir. \(movie.director)")
        }

        Not Preferred

        let movie = item as! Movie
        print("Movie: '\(movie.name)', dir. \(movie.director)")

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                if PrefsInfo.weather.degree == .celsius {
                    if PrefsInfo.weatherWindMode == .kph {
                        textWind.string = "\(Int(wind.speed * 3.6)) km/h"
                    } else {
                        textWind.string = "\(Int(wind.speed)) m/s"
        Severity: Minor
        Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift and 1 other location - About 45 mins to fix
        Aerial/Source/Views/Layers/Weather/ForecastLayer.swift on lines 364..372

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 57.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                humidityBlock.frame.size = CGSize(width: textHumidity.frame.width+imglayer.frame.width,
                                                  height: max(textHumidity.frame.height, imglayer.frame.height))
        Severity: Minor
        Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift and 1 other location - About 35 mins to fix
        Aerial/Source/Views/Layers/Weather/ConditionLayer.swift on lines 297..298

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 47.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                windBlock.frame.size = CGSize(width: textWind.frame.width+imglayer.frame.width,
                                              height: max(textWind.frame.height, imglayer.frame.height))
        Severity: Minor
        Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift and 1 other location - About 35 mins to fix
        Aerial/Source/Views/Layers/Weather/ConditionLayer.swift on lines 247..248

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 47.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    humidityBlock!.position = CGPoint(x: x + halfTotalWidth - humidityBlock!.frame.size.width/2, y: y)
        Severity: Minor
        Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift and 1 other location - About 30 mins to fix
        Aerial/Source/Views/Layers/Weather/ConditionLayer.swift on lines 192..192

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 42.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    windBlock!.position = CGPoint(x: x - halfTotalWidth + windBlock!.frame.size.width/2, y: y)
        Severity: Minor
        Found in Aerial/Source/Views/Layers/Weather/ConditionLayer.swift and 1 other location - About 30 mins to fix
        Aerial/Source/Views/Layers/Weather/ConditionLayer.swift on lines 193..193

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 42.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function should have at least one blank line after it
        Open

            }

        function-whitespace

        Every function and method declaration should have one blank line before and after itself. An exception to this rule are functions that are declared at the start of a file (only need one blank line after their declaration) or at the end of a file (only need one blank line before their declaration). Comments immediately before a function declaration (no blank lines between them and the function) are considered to be part of the declaration.

        Preferred

        func function1() {
          var text = 1
          var text = 2
        }
        
        function1()
        
        // a comment
        func function2() {
          // something goes here
        }
        
        struct SomeStruct {
        
          func function3() {
            // something goes here
          }
        
          func function4() {
            // something else goes here
          };
        
        }
        
        func function5() {
          // something goes here
        }

        Not Preferred

        func function1() {
          var text = 1
          var text = 2
        }
        function1()
        // a comment
        func function2() {
          // something goes here
        }
        
        struct SomeStruct {
          func function3() {
            // something goes here
          }
        
          func function4() {
            // something else goes here
          };
        }
        func function5() {
          // something goes here
        }

        There are no issues that match your filters.

        Category
        Status