Function cookieFrom
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
func cookieFrom(response: ClientResponse?, named: String) -> (HTTPCookie?, String?) {
guard let response = response else {
return (nil, nil)
}
var resultCookie: HTTPCookie? = nil
- 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 testCookieFromServer
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
func testCookieFromServer() {
performServerTest(router, asyncTasks: { expectation in
self.performRequest("get", path: "/1/sendcookie", callback: {response in
XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "/1/sendcookie route did not match single path request")
File TestCookies.swift
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
import XCTest
import Foundation
#if swift(>=4.1)
#if canImport(FoundationNetworking)
import FoundationNetworking
Function testCookieFromServer
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
func testCookieFromServer() {
performServerTest(router, asyncTasks: { expectation in
self.performRequest("get", path: "/1/sendcookie", callback: {response in
XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "/1/sendcookie route did not match single path request")
- 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 cookieFrom
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
func cookieFrom(response: ClientResponse?, named: String) -> (HTTPCookie?, String?) {
guard let response = response else {
return (nil, nil)
}
var resultCookie: HTTPCookie? = nil
Function testNoCookies
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
func testNoCookies() {
performServerTest(router, asyncTasks: { expectation in
self.performRequest("get", path: "/1/cookiedump", callback: {response in
XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "cookiedump route did not match single path request")
do {
- 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 setupRouter
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
static func setupRouter() -> Router {
let router = Router()
router.get("/1/cookiedump") {request, response, next in
var cookies: [String] = []
Function cookieToServer
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private func cookieToServer(separator: String, quoteValue: Bool) {
performServerTest(router, asyncTasks: { expectation in
let cookieMap = [" Plover ": " value with spaces ",
"Zxcv": "(E = mc^2)",
"value with one quote": "\"",
- 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 cookieToServer
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private func cookieToServer(separator: String, quoteValue: Bool) {
performServerTest(router, asyncTasks: { expectation in
let cookieMap = [" Plover ": " value with spaces ",
"Zxcv": "(E = mc^2)",
"value with one quote": "\"",
Function testNoCookies
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
func testNoCookies() {
performServerTest(router, asyncTasks: { expectation in
self.performRequest("get", path: "/1/cookiedump", callback: {response in
XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "cookiedump route did not match single path request")
do {
Avoid deeply nested control flow statements. Open
for part in parts[1..<parts.count] {
let pieces = part.components(separatedBy: "=")
let piece = pieces[0].lowercased()
switch piece {
case "secure", "httponly":
Identical blocks of code found in 2 locations. Consider refactoring. Open
/**
* Copyright IBM Corporation 2016
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- 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 121.
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 cookie1 = cookie1 {
XCTAssertEqual(cookie1.value, cookie1Value as String, "Value of Cookie \(cookie1Name) is not \(cookie1Value), was \(cookie1.value)")
XCTAssertEqual(cookie1.path, "/", "Path of Cookie \(cookie1Name) is not (/), was \(cookie1.path)")
XCTAssertEqual(cookie1.domain, cookieHost as String, "Domain of Cookie \(cookie1Name) is not \(cookieHost), was \(cookie1.domain)")
XCTAssertFalse(cookie1.isSecure, "\(cookie1Name) was marked as secure. Should have not been marked so.")
- 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 89.
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 cookie = cookie {
XCTAssertEqual(cookie.value, cookie3Value as String, "Value of Cookie \(cookie3Name) is not \(cookie3Value), was \(cookie.value)")
XCTAssertEqual(cookie.path, "/", "Path of Cookie \(cookie3Name) is not (/), was \(cookie.path)")
XCTAssertEqual(cookie.domain, cookieHost as String, "Domain of Cookie \(cookie3Name) is not \(cookieHost), was \(cookie.domain)")
XCTAssertTrue(cookie.isSecure, "\(cookie3Name) wasn't marked as secure. It should have been marked so.")
- 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 89.
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
static var allTests: [(String, (TestCookies) -> () throws -> Void)] {
return [
("testCookieToServerWithSemiColonSeparator", testCookieToServerWithSemiColonSeparator),
("testCookieToServerWithSemiColonSpaceSeparator", testCookieToServerWithSemiColonSpaceSeparator),
("testCookieToServerWithSemiColonWhitespacesSeparator", testCookieToServerWithSemiColonWhitespacesSeparator),
- 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 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
- 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
Parameter clause in closure signature should be preceded by exactly one space Open
self.performRequest("get", path: "/1/sendcookie", callback: {response in
- Exclude checks
Closure is the function's final argument and may be passed as a trailing closure instead Open
}, { expectation in
- Read upRead up
- Exclude checks
trailing-closure
Closures that are the last argument of a function should be passed into the function using trailing closure syntax.
Preferred
reversed = names.sort { s1, s2 in return s1 > s2 }
Not Preferred
reversed = names.sort({ s1, s2 in return s1 > s2 })
Parameter clause in closure signature should be preceded by exactly one space Open
router.get("/2/sendcookie") {request, response, next in
- Exclude checks
Parameter clause in closure signature should be preceded by exactly one space Open
self.performRequest("get", path: "/1/cookiedump", callback: {response in
- Exclude checks
Parameter clause in closure signature should be preceded by exactly one space Open
self.performRequest("get", path: "/1/cookiedump", callback: {response in
- Exclude checks
Parameter clause in closure signature should be preceded by exactly one space Open
router.get("/1/cookiedump") {request, response, next in
- Exclude checks
Parameter clause in closure signature should be preceded by exactly one space Open
router.get("/3/sendcookie") {request, response, next in
- Exclude checks
Parameter clause in closure signature should be preceded by exactly one space Open
self.performRequest("get", path: "/1/cookiedump", callback: {response in
- Exclude checks
Closure is the function's final argument and may be passed as a trailing closure instead Open
}, { expectation in
- Read upRead up
- Exclude checks
trailing-closure
Closures that are the last argument of a function should be passed into the function using trailing closure syntax.
Preferred
reversed = names.sort { s1, s2 in return s1 > s2 }
Not Preferred
reversed = names.sort({ s1, s2 in return s1 > s2 })
Parameter clause in closure signature should be preceded by exactly one space Open
router.get("/1/sendcookie") {request, response, next in
- Exclude checks