Kinvey/swift-sdk

View on GitHub
Kinvey/Kinvey/FindOperation.swift

Summary

Maintainability
F
4 days
Test Coverage

File FindOperation.swift has 403 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Foundation
import PromiseKit

private let MaxIdsPerQuery = 200
private let MaxSizePerResultSet = 10_000
Severity: Minor
Found in Kinvey/Kinvey/FindOperation.swift - About 5 hrs to fix

    Function fetchAll has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        private func fetchAll(multiRequest: MultiRequest<ResultType>) -> Promise<AnyRandomAccessCollection<T>> {
            return Promise<AnyRandomAccessCollection<T>> { resolver in
                let request = client.networkRequestFactory.appData.buildAppDataFindByQuery(
                    collectionName: try! T.collectionName(),
                    query: query,
    Severity: Minor
    Found in Kinvey/Kinvey/FindOperation.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 fetchDelta has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        private func fetchDelta(multiRequest: MultiRequest<ResultType>, sinceDate: Date) -> Promise<AnyRandomAccessCollection<T>> {
            return Promise<AnyRandomAccessCollection<T>> { resolver in
                let request = client.networkRequestFactory.appData.buildAppDataFindByQueryDeltaSet(
                    collectionName: try! T.collectionName(),
                    query: query,
    Severity: Minor
    Found in Kinvey/Kinvey/FindOperation.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 fetchAutoPagination has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        private func fetchAutoPagination(multiRequest: MultiRequest<ResultType>, count: Int, requestStart: Date?) -> Promise<AnyRandomAccessCollection<T>> {
            return Promise<AnyRandomAccessCollection<T>> { resolver in
                let maxSizePerResultSet = options?.maxSizePerResultSet ?? MaxSizePerResultSet
                let nPages = Int64(ceil(Double(count) / Double(maxSizePerResultSet)))
                let progress = Progress(totalUnitCount: nPages + 1, parent: multiRequest.progress, pendingUnitCount: 99)
    Severity: Minor
    Found in Kinvey/Kinvey/FindOperation.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 fetchDelta has 75 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private func fetchDelta(multiRequest: MultiRequest<ResultType>, sinceDate: Date) -> Promise<AnyRandomAccessCollection<T>> {
            return Promise<AnyRandomAccessCollection<T>> { resolver in
                let request = client.networkRequestFactory.appData.buildAppDataFindByQueryDeltaSet(
                    collectionName: try! T.collectionName(),
                    query: query,
    Severity: Major
    Found in Kinvey/Kinvey/FindOperation.swift - About 3 hrs to fix

      Function fetchAutoPagination has 58 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private func fetchAutoPagination(multiRequest: MultiRequest<ResultType>, count: Int, requestStart: Date?) -> Promise<AnyRandomAccessCollection<T>> {
              return Promise<AnyRandomAccessCollection<T>> { resolver in
                  let maxSizePerResultSet = options?.maxSizePerResultSet ?? MaxSizePerResultSet
                  let nPages = Int64(ceil(Double(count) / Double(maxSizePerResultSet)))
                  let progress = Progress(totalUnitCount: nPages + 1, parent: multiRequest.progress, pendingUnitCount: 99)
      Severity: Major
      Found in Kinvey/Kinvey/FindOperation.swift - About 2 hrs to fix

        Function fetchAll has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private func fetchAll(multiRequest: MultiRequest<ResultType>) -> Promise<AnyRandomAccessCollection<T>> {
                return Promise<AnyRandomAccessCollection<T>> { resolver in
                    let request = client.networkRequestFactory.appData.buildAppDataFindByQuery(
                        collectionName: try! T.collectionName(),
                        query: query,
        Severity: Major
        Found in Kinvey/Kinvey/FindOperation.swift - About 2 hrs to fix

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

              private func count(multiRequest: MultiRequest<ResultType>) -> Promise<(count: Int, requestStart: Date?)?> {
                  return Promise<(count: Int, requestStart: Date?)?> { resolver in
                      if !deltaSet, autoPagination {
                          if let limit = query.limit {
                              resolver.fulfill((count: limit, requestStart: nil))
          Severity: Minor
          Found in Kinvey/Kinvey/FindOperation.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 count has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private func count(multiRequest: MultiRequest<ResultType>) -> Promise<(count: Int, requestStart: Date?)?> {
                  return Promise<(count: Int, requestStart: Date?)?> { resolver in
                      if !deltaSet, autoPagination {
                          if let limit = query.limit {
                              resolver.fulfill((count: limit, requestStart: nil))
          Severity: Minor
          Found in Kinvey/Kinvey/FindOperation.swift - About 1 hr to fix

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

                func convertToEntities(fromJsonArray jsonArray: [JsonDictionary]) throws -> AnyRandomAccessCollection<T> {
                    signpost(.begin, log: osLog, name: "Convert Entities")
                    defer {
                        signpost(.end, log: osLog, name: "Convert Entities")
                    }
            Severity: Minor
            Found in Kinvey/Kinvey/FindOperation.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 executeNetwork has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                @discardableResult
                func executeNetwork(_ completionHandler: CompletionHandler? = nil) -> AnyRequest<ResultType> {
                    let request = MultiRequest<ResultType>()
                    request.progress = Progress(totalUnitCount: 100)
                    count(multiRequest: request).then { (args) -> Promise<AnyRandomAccessCollection<T>> in
            Severity: Minor
            Found in Kinvey/Kinvey/FindOperation.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 Promise<AnyRandomAccessCollection<T>>(error: error)
            Severity: Major
            Found in Kinvey/Kinvey/FindOperation.swift - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                  return self.fetchAllAutoPagination(multiRequest: multiRequest)
              Severity: Major
              Found in Kinvey/Kinvey/FindOperation.swift - About 30 mins to fix

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

                                    let request = countOperation.execute { result in
                                        switch result {
                                        case .success(let count):
                                            resolver.fulfill((count: count, requestStart: requestStart))
                                        case .failure(let error):
                Severity: Minor
                Found in Kinvey/Kinvey/FindOperation.swift and 1 other location - About 50 mins to fix
                Kinvey/Kinvey/DataStore.swift on lines 1095..1102

                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 args = args {
                                let (count, requestStart) = args
                                return self.fetchAutoPagination(multiRequest: request, count: count, requestStart: requestStart)
                            } else {
                                return self.fetch(multiRequest: request)
                Severity: Minor
                Found in Kinvey/Kinvey/FindOperation.swift and 1 other location - About 40 mins to fix
                Kinvey/Kinvey/FindOperation.swift on lines 387..392

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

                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 args = args {
                                let (count, requestStart) = args
                                return self.fetchAutoPagination(multiRequest: multiRequest, count: count, requestStart: requestStart)
                            } else {
                                return self.fetchAll(multiRequest: multiRequest)
                Severity: Minor
                Found in Kinvey/Kinvey/FindOperation.swift and 1 other location - About 40 mins to fix
                Kinvey/Kinvey/FindOperation.swift on lines 402..407

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

                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

                        }.done { results in
                            let result: ResultType = .success(results)
                            if self.mustSetRequestResult {
                                request.result = result
                            }
                Severity: Minor
                Found in Kinvey/Kinvey/FindOperation.swift and 1 other location - About 35 mins to fix
                Kinvey/Kinvey/FindOperation.swift on lines 414..420

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

                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

                        }.catch {
                            let result: ResultType = .failure($0)
                            if self.mustSetRequestResult {
                                request.result = result
                            }
                Severity: Minor
                Found in Kinvey/Kinvey/FindOperation.swift and 1 other location - About 35 mins to fix
                Kinvey/Kinvey/FindOperation.swift on lines 408..414

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

                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 6 locations. Consider refactoring.
                Open

                //
                //  FindOperation.swift
                //  Kinvey
                //
                //  Created by Victor Barros on 2016-02-15.
                Severity: Major
                Found in Kinvey/Kinvey/FindOperation.swift and 5 other locations - About 30 mins to fix
                Kinvey/Kinvey/DataStore.swift on lines 1..1341
                Kinvey/Kinvey/DataStore.swift on lines 1..1341
                Kinvey/Kinvey/DataStore.swift on lines 1..1341
                Kinvey/Kinvey/DataStore.swift on lines 1..1341
                Kinvey/Kinvey/DataStore.swift on lines 1..1341

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

                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