JohnCoates/Aerial

View on GitHub
Aerial/Source/Models/Cache/Cache.swift

Summary

Maintainability
F
4 days
Test Coverage

File Cache.swift has 519 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Cocoa
import CoreWLAN
import AVKit

/**
Severity: Major
Found in Aerial/Source/Models/Cache/Cache.swift - About 1 day to fix

    Function freeCache has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        static func freeCache() {
            guard PrefsCache.enableManagement else {
                return
            }
    
    
    Severity: Minor
    Found in Aerial/Source/Models/Cache/Cache.swift - About 5 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 freeCache has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static func freeCache() {
            guard PrefsCache.enableManagement else {
                return
            }
    
    
    Severity: Major
    Found in Aerial/Source/Models/Cache/Cache.swift - About 2 hrs to fix

      Function removeCruft has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          static func removeCruft() {
              // TODO: kind of a temporary safety
              if VideoList.instance.videos.count > 90 {
                  // First let's look at the cache
      
      
      Severity: Minor
      Found in Aerial/Source/Models/Cache/Cache.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 removeUncachedCruft has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          static func removeUncachedCruft() {
              for source in SourceList.foundSources where !source.isCachable && source.type != .local {
                  debugLog("Checking cruft in \(source.name)")
      
                  let pathURL = URL(fileURLWithPath: supportPath.appending("/" + source.name))
      Severity: Minor
      Found in Aerial/Source/Models/Cache/Cache.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 ensureDownload has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          static func ensureDownload(action: @escaping () -> Void) {
              // Do we manage the cache or not ?
              if PrefsCache.enableManagement {
                  // Check network first
                  if !canNetwork() {
      Severity: Minor
      Found in Aerial/Source/Models/Cache/Cache.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 removeCruft has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static func removeCruft() {
              // TODO: kind of a temporary safety
              if VideoList.instance.videos.count > 90 {
                  // First let's look at the cache
      
      
      Severity: Minor
      Found in Aerial/Source/Models/Cache/Cache.swift - About 1 hr to fix

        Function removeUncachedCruft has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static func removeUncachedCruft() {
                for source in SourceList.foundSources where !source.isCachable && source.type != .local {
                    debugLog("Checking cruft in \(source.name)")
        
                    let pathURL = URL(fileURLWithPath: supportPath.appending("/" + source.name))
        Severity: Minor
        Found in Aerial/Source/Models/Cache/Cache.swift - About 1 hr to fix

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

              static func clearNonCacheableSources() {
                  // Then we need to look at individual online sources
                  // let onlineVideos = VideoList.instance.videos.filter({ !$0.source.isCachable })
          
                  for source in SourceList.foundSources.filter({!$0.isCachable}) {
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.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

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

              static private func migrateOldCache() {
                  if let formerCachePath = formerCachePath {
                      do {
                          let formerCacheURL = URL(fileURLWithPath: formerCachePath as String)
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.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

          Function canNetwork has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              static func canNetwork() -> Bool {
                  if !PrefsCache.enableManagement {
                      return true
                  }
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift - About 35 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

          Function fillOrRollCache has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              static func fillOrRollCache() {
                  guard PrefsCache.enableManagement && canNetwork() else {
                      return
                  }
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift - About 35 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

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

              static func outdatedVideos() -> [AerialVideo] {
                  guard PrefsCache.enableManagement else {
                      return []
                  }
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.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

                  if FileManager.default.fileExists(atPath: directory) {
                      let pathURL = URL(fileURLWithPath: directory)
          
                      // check if the url is a directory
                      if (try? pathURL.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true {
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 2 hrs to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 554..568

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

          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 func size() -> Double {
                  let pathURL = URL(fileURLWithPath: path)
          
                  // check if the url is a directory
                  if (try? pathURL.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true {
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 2 hrs to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 571..585

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

          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

                          if !videoURLs.isEmpty {
                              debugLog("Starting migration of your video files from Caches to the /Cache subfolder of Application Support")
                              for videoURL in videoURLs {
                                  debugLog("moving \(videoURL.lastPathComponent)")
                                  let newURL = URL(fileURLWithPath: path.appending("/\(videoURL.lastPathComponent)"))
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 1 hr to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 335..343

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

          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

                      if !videoURLs.isEmpty {
                          debugLog("Starting migration of your video files from Application Support to the /Cache subfolder")
                          for videoURL in videoURLs {
                              debugLog("moving \(videoURL.lastPathComponent)")
                              let newURL = URL(fileURLWithPath: path.appending("/\(videoURL.lastPathComponent)"))
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 1 hr to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 361..369

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

          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

                  if FileManager.default.fileExists(atPath: path as String) {
                      return path
                  } else {
                      do {
                          try FileManager.default.createDirectory(atPath: path,
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 1 hr to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 262..273

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

          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

                  if FileManager.default.fileExists(atPath: path as String) {
                      return path
                  } else {
                      do {
                          try FileManager.default.createDirectory(atPath: path,
          Severity: Major
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 1 hr to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 218..229

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

          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

                      if VideoList.instance.currentRotation().contains(video) {
                          // Outdated but in rotation, so keep it !
                          // debugLog("outdated but in rotation \(video.secondaryName)")
                      } else {
                          debugLog("Removing outdated video not in rotation \(video.secondaryName)")
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 50 mins to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 772..786

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

          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

                      if currentVideos.contains(video) {
                          debugLog("\(video.secondaryName) is currently playing, trying another")
                      } else {
                          debugLog("Removing outdated video that was in rotation \(video.secondaryName)")
                          do {
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 50 mins to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 738..753

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

          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

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

                          } else {
                              let appSupportPaths = NSSearchPathForDirectoriesInDomains(
                                  .applicationSupportDirectory,
                                  .userDomainMask,
                                  true)
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 40 mins to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 103..116

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

          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

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

                      if !Aerial.helper.underCompanion {
                          // Grab an array of Application Support paths
                          let appSupportPaths = NSSearchPathForDirectoriesInDomains(
                              .applicationSupportDirectory,
                              .userDomainMask,
          Severity: Minor
          Found in Aerial/Source/Models/Cache/Cache.swift and 1 other location - About 40 mins to fix
          Aerial/Source/Models/Cache/Cache.swift on lines 126..137

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

          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