JohnCoates/Aerial

View on GitHub
Aerial/Source/Views/AerialView.swift

Summary

Maintainability
F
6 days
Test Coverage

File AerialView.swift has 717 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Foundation
import ScreenSaver
import AVFoundation
import AVKit

Severity: Major
Found in Aerial/Source/Views/AerialView.swift - About 1 day to fix

    Function setup has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

        func setup() {
            // Disable HDR only on macOS Ventura
            if !Aerial.helper.canHDR() {
                if isPreview && (PrefsVideos.videoFormat == .v4KHDR || PrefsVideos.videoFormat == .v1080pHDR) {
                    // This will lead to crashing in up to Ventura beta5 so disable
    Severity: Minor
    Found in Aerial/Source/Views/AerialView.swift - About 7 hrs 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

    Function setup has 115 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        func setup() {
            // Disable HDR only on macOS Ventura
            if !Aerial.helper.canHDR() {
                if isPreview && (PrefsVideos.videoFormat == .v4KHDR || PrefsVideos.videoFormat == .v1080pHDR) {
                    // This will lead to crashing in up to Ventura beta5 so disable
    Severity: Major
    Found in Aerial/Source/Views/AerialView.swift - About 4 hrs to fix

      Function keyDown has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          override func keyDown(with event: NSEvent) {
              debugLog("🖼️ keyDown")
      
              if PrefsVideos.allowSkips {
                  if event.keyCode == 124 {
      Severity: Minor
      Found in Aerial/Source/Views/AerialView.swift - About 3 hrs 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

      Function playNextVideo has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          func playNextVideo() {
              debugLog("🖼️ \(self) pnv")
      
              clearAllLayerAnimations()
      
      
      Severity: Minor
      Found in Aerial/Source/Views/AerialView.swift - About 3 hrs 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

      AerialView has 30 methods (exceeds 20 allowed). Consider refactoring.
      Open

      @objc(AerialView)
      // swiftlint:disable:next type_body_length
      final class AerialView: ScreenSaverView, CAAnimationDelegate {
          var layerManager: LayerManager
          var playerLayer: AVPlayerLayer!
      Severity: Minor
      Found in Aerial/Source/Views/AerialView.swift - About 3 hrs to fix

        Function playNextVideo has 80 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func playNextVideo() {
                debugLog("🖼️ \(self) pnv")
        
                clearAllLayerAnimations()
        
        
        Severity: Major
        Found in Aerial/Source/Views/AerialView.swift - About 3 hrs to fix

          Function observeValue has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
          Open

              internal override func observeValue(forKeyPath keyPath: String?,
                                                  of object: Any?, change: [NSKeyValueChangeKey: Any]?,
                                                  context: UnsafeMutableRawPointer?) {
                  debugLog("🖼️ \(description) observeValue \(String(describing: keyPath)) \(playerLayer.isReadyForDisplay)")
          
          
          Severity: Minor
          Found in Aerial/Source/Views/AerialView.swift - About 2 hrs 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

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

              internal override func observeValue(forKeyPath keyPath: String?,
                                                  of object: Any?, change: [NSKeyValueChangeKey: Any]?,
                                                  context: UnsafeMutableRawPointer?) {
                  debugLog("🖼️ \(description) observeValue \(String(describing: keyPath)) \(playerLayer.isReadyForDisplay)")
          
          
          Severity: Minor
          Found in Aerial/Source/Views/AerialView.swift - About 1 hr to fix

            Function screenIsUnlocked has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                @objc func screenIsUnlocked(_ aNotification: Notification) {
                    if #available(macOS 14.0, *) {
                        debugLog("🖼️ 📢📢📢 ☢️sonoma☢️ workaround screenIsUnlocked")
                        if !Aerial.helper.underCompanion {
                            if let player = player {
            Severity: Minor
            Found in Aerial/Source/Views/AerialView.swift - About 1 hr 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

            Function setNotifications has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                func setNotifications(_ currentItem: AVPlayerItem) {
                    let notificationCenter = NotificationCenter.default
            
                    notificationCenter.addObserver(self,
                                                   selector: #selector(AerialView.playerItemDidReachEnd(_:)),
            Severity: Minor
            Found in Aerial/Source/Views/AerialView.swift - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                      for view in AerialView.instanciatedViews {
                                          view.fastFadeOut(andPlayNext: true)
                                      }
              Severity: Major
              Found in Aerial/Source/Views/AerialView.swift - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        for view in AerialView.sharedViews where AerialView.sharedViews.first != view {
                                            view.fastFadeOut(andPlayNext: false)
                                        }
                Severity: Major
                Found in Aerial/Source/Views/AerialView.swift - About 45 mins to fix

                  Function willStop has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      @objc func willStop(_ aNotification: Notification) {
                          DisplayDetection.sharedInstance.resetUnusedScreens()
                  
                  /*        if #available(macOS 14.0, *) {
                              debugLog("🖼️ 📢📢📢 🖼️ 📢📢📢 ☢️sonoma☢️ workaround IGNORING willStop")
                  Severity: Minor
                  Found in Aerial/Source/Views/AerialView.swift - About 45 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
                  Severity: Major
                  Found in Aerial/Source/Views/AerialView.swift - About 30 mins to fix

                    Function cleanupSharedViews has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        func cleanupSharedViews() {
                            if AerialView.singlePlayerAlreadySetup {
                                if let index = AerialView.sharedPlayerIndex {
                                    if AerialView.instanciatedViews[index].wasStopped {
                                        AerialView.singlePlayerAlreadySetup = false
                    Severity: Minor
                    Found in Aerial/Source/Views/AerialView.swift - About 25 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

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

                        static var textFadeDuration: Double {
                            switch PrefsInfo.fadeModeText {
                            case .t0_5:
                                return 0.5
                            case .t1:
                    Severity: Minor
                    Found in Aerial/Source/Views/AerialView.swift and 1 other location - About 40 mins to fix
                    Aerial/Source/Views/AerialView.swift on lines 55..66

                    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 49.

                    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

                        static var fadeDuration: Double {
                            switch PrefsVideos.fadeMode {
                            case .t0_5:
                                return 0.5
                            case .t1:
                    Severity: Minor
                    Found in Aerial/Source/Views/AerialView.swift and 1 other location - About 40 mins to fix
                    Aerial/Source/Views/AerialView.swift on lines 68..79

                    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 49.

                    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

                    There are no issues that match your filters.

                    Category
                    Status