JohnCoates/Aerial

View on GitHub
Aerial/Source/Models/Sources/VideoList.swift

Summary

Maintainability
F
4 days
Test Coverage

File VideoList.swift has 436 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Foundation

typealias VideoListRefreshCallback = () -> Void
extension RangeReplaceableCollection {
    /// Returns a collection containing, in order, the first instances of
Severity: Minor
Found in Aerial/Source/Models/Sources/VideoList.swift - About 6 hrs to fix

    VideoList has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class VideoList {
        enum FilterMode {
            case location, cache, time, scene, source, rotation, favorite, hidden
        }
    
    
    Severity: Minor
    Found in Aerial/Source/Models/Sources/VideoList.swift - About 2 hrs to fix

      Function filteredVideosFor has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private func filteredVideosFor(_ mode: FilterMode, filter: [String]) -> [AerialVideo] {
              // Our preference filters contains ALL sorts of filters (location, time) that are
              // saved for better user experience. So we need to filter the filters first !
              var filters: [String] = []
      
      
      Severity: Major
      Found in Aerial/Source/Models/Sources/VideoList.swift - About 2 hrs to fix

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

            private func filteredVideosFor(_ mode: FilterMode, filter: [String]) -> [AerialVideo] {
                // Our preference filters contains ALL sorts of filters (location, time) that are
                // saved for better user experience. So we need to filter the filters first !
                var filters: [String] = []
        
        
        Severity: Minor
        Found in Aerial/Source/Models/Sources/VideoList.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 generatePlaylist has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            func generatePlaylist(isRestricted: Bool, restrictedTo: String, isVertical: Bool) {
                debugLog("generate playlist (isVertical: \(isVertical)")
                // Start fresh
                playlist = [AerialVideo]()
                playlistIsRestricted = isRestricted
        Severity: Minor
        Found in Aerial/Source/Models/Sources/VideoList.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 randomVideo has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            func randomVideo(excluding: [AerialVideo], isVertical: Bool) -> (AerialVideo?, Bool) {
                var shouldLoop = false
                let timeManagement = TimeManagement.sharedInstance
        
                let (shouldRestrictByDayNight, restrictTo) = timeManagement.shouldRestrictPlaybackToDayNightVideo()
        Severity: Minor
        Found in Aerial/Source/Models/Sources/VideoList.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 downloadManifestsIfNeeded has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            private func downloadManifestsIfNeeded() {
                let downloadManager = DownloadManager()
        
                var sourceQueue: [Source] = []
        
        
        Severity: Minor
        Found in Aerial/Source/Models/Sources/VideoList.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 filteredVideosFor has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private func filteredVideosFor(_ mode: FilterMode, section: Int) -> [AerialVideo] {
                switch mode {
                case .location:
                    let filter = sourcesFor(mode)[section].lowercased()
                    return videos
        Severity: Minor
        Found in Aerial/Source/Models/Sources/VideoList.swift - About 1 hr to fix

          Function downloadManifestsIfNeeded has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private func downloadManifestsIfNeeded() {
                  let downloadManager = DownloadManager()
          
                  var sourceQueue: [Source] = []
          
          
          Severity: Minor
          Found in Aerial/Source/Models/Sources/VideoList.swift - About 1 hr to fix

            Function findBestEffortVideo has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                func findBestEffortVideo() -> AerialVideo? {
                    // So this is embarassing. This can happen if :
                    // - No video checked
                    // - No video for current conditions (only day video checked, and looking for night)
                    // - We don't want to stream but don't have any video
            Severity: Minor
            Found in Aerial/Source/Models/Sources/VideoList.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 generatePlaylist has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                func generatePlaylist(isRestricted: Bool, restrictedTo: String, isVertical: Bool) {
                    debugLog("generate playlist (isVertical: \(isVertical)")
                    // Start fresh
                    playlist = [AerialVideo]()
                    playlistIsRestricted = isRestricted
            Severity: Minor
            Found in Aerial/Source/Models/Sources/VideoList.swift - About 1 hr to fix

              Function randomVideo has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  func randomVideo(excluding: [AerialVideo], isVertical: Bool) -> (AerialVideo?, Bool) {
                      var shouldLoop = false
                      let timeManagement = TimeManagement.sharedInstance
              
                      let (shouldRestrictByDayNight, restrictTo) = timeManagement.shouldRestrictPlaybackToDayNightVideo()
              Severity: Minor
              Found in Aerial/Source/Models/Sources/VideoList.swift - About 1 hr to fix

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

                    func modeFromPath(_ path: String) -> FilterMode? {
                        if path.starts(with: "location") {
                            return .location
                        } else if path.starts(with: "cache") {
                            return .cache
                Severity: Minor
                Found in Aerial/Source/Models/Sources/VideoList.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 refreshVideoList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    private func refreshVideoList() {
                        debugLog("Refreshing video list")
                
                        videos = []
                
                
                Severity: Minor
                Found in Aerial/Source/Models/Sources/VideoList.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

                Avoid too many return statements within this function.
                Open

                            return .source
                Severity: Major
                Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return .favorite
                  Severity: Major
                  Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return shuffled.first!
                    Severity: Major
                    Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return videos
                                          .filter({ $0.isAvailableOffline && !PrefsVideos.hidden.contains($0.id) })
                                          .sorted { $0.secondaryName < $1.secondaryName }
                      Severity: Major
                      Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return .hidden
                        Severity: Major
                        Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return videos
                                              .filter({ !$0.isAvailableOffline && !PrefsVideos.hidden.contains($0.id) })
                                              .sorted { $0.secondaryName < $1.secondaryName }
                          Severity: Major
                          Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return .rotation
                            Severity: Major
                            Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return nil
                              Severity: Major
                              Found in Aerial/Source/Models/Sources/VideoList.swift - About 30 mins to fix

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

                                //
                                //  VideoList.swift
                                //  Aerial
                                //
                                //  Created by Guillaume Louel on 08/07/2020.
                                Severity: Minor
                                Found in Aerial/Source/Models/Sources/VideoList.swift and 1 other location - About 55 mins to fix
                                Aerial/Source/Models/Sources/VideoList.swift on lines 1..598

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

                                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

                                            let vids = videos
                                                .filter { filters.contains($0.name.lowercased()) && !PrefsVideos.hidden.contains($0.id) }
                                                .sorted { $0.secondaryName < $1.secondaryName }
                                Severity: Minor
                                Found in Aerial/Source/Models/Sources/VideoList.swift and 1 other location - About 50 mins to fix
                                Aerial/Source/Models/Sources/VideoList.swift on lines 189..191

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

                                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

                                            return videos
                                                .filter { filters.contains($0.timeOfDay.lowercased()) && !PrefsVideos.hidden.contains($0.id) }
                                                .sorted { $0.secondaryName < $1.secondaryName }
                                Severity: Minor
                                Found in Aerial/Source/Models/Sources/VideoList.swift and 1 other location - About 50 mins to fix
                                Aerial/Source/Models/Sources/VideoList.swift on lines 184..186

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

                                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 let mode = VideoList.instance.modeFromPath(path) {
                                            let index = Int(path.split(separator: ":")[1])!
                                            return VideoList.instance.getVideosForSource(index, mode: mode)
                                        } else {
                                            // all
                                Severity: Minor
                                Found in Aerial/Source/Models/Sources/VideoList.swift and 1 other location - About 40 mins to fix
                                Resources/MainUI/VideosViewController.swift on lines 688..694

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

                                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