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
VideoList
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class VideoList {
enum FilterMode {
case location, cache, time, scene, source, rotation, favorite, hidden
}
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] = []
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] = []
- Read upRead up
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
- Read upRead up
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()
- Read upRead up
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] = []
- Read upRead up
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
Function downloadManifestsIfNeeded
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private func downloadManifestsIfNeeded() {
let downloadManager = DownloadManager()
var sourceQueue: [Source] = []
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
- Read upRead up
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
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()
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
- Read upRead up
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 = []
- Read upRead up
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
Avoid too many return
statements within this function. Open
return .favorite
Avoid too many return
statements within this function. Open
return shuffled.first!
Avoid too many return
statements within this function. Open
return videos
.filter({ $0.isAvailableOffline && !PrefsVideos.hidden.contains($0.id) })
.sorted { $0.secondaryName < $1.secondaryName }
Avoid too many return
statements within this function. Open
return .hidden
Avoid too many return
statements within this function. Open
return videos
.filter({ !$0.isAvailableOffline && !PrefsVideos.hidden.contains($0.id) })
.sorted { $0.secondaryName < $1.secondaryName }
Avoid too many return
statements within this function. Open
return .rotation
Avoid too many return
statements within this function. Open
return nil
Identical blocks of code found in 2 locations. Consider refactoring. Open
//
// VideoList.swift
// Aerial
//
// Created by Guillaume Louel on 08/07/2020.
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 }
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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 }
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76